I’m trying to write a unit test for a saga (my first NSB unit-test).
I want the unit-test to be able to test all the timeouts that happen during that Saga and I want to be able to debug it and have the debugger’s breakpoint to hit on every method.
Here is my Saga with all the relevant methods and timeouts that I want to test and be able to debug:
public class MySaga : SqlSaga<MySagaData>,
IAmStartedByMessages<StartTheSaga>,
IHandleMessages<RetryMethod>,
IHandleTimeouts<TimeoutMethod>
{
public async Task Handle(StartTheSaga message, IMessageHandlerContext context)
{
...
await RequestTimeout<TimeoutMethod>(context, timeSpan).ConfigureAwait(false);
}
public async Task Timeout(TimeoutMethod state, IMessageHandlerContext context)
{
...
await context.SendLocal<CheckSomething>(...).ConfigureAwait(false);
}
public Task Handle(CheckSomething message, IMessageHandlerContext context)
{
context.SendLocal<RetryMethod>(...);
return Task.CompletedTask;
}
public async Task Handle(RetryMethod message, IMessageHandlerContext context)
{
...
await RequestTimeout<TimeoutMethod>(context, timeSpan).ConfigureAwait(false);
}
}
Here is my unit-test code for that Saga, it contains commented calls that I’ve tried and didn’t work, maybe I didn’t configure them properly?
public void TestMySaga()
{
Test.Saga(new MySaga()
{
Data = new MySagaData() { }
})
.ExpectTimeoutToBeSetAt<TimeoutMethod>()
.ExpectTimeoutToBeSetIn<IStartTheSaga>(
check: (state, span) =>
{
return span == TimeSpan.Parse("00:00:05");
}
)
.WhenHandling<IStartTheSaga>(message => { //FILL IN MESSAGE DATA })
//.WhenHandlingTimeout<TimeoutMethod>();
//.WhenSagaTimesOut();
}
How can I get this to work (if possible)?