Saga and unit tests

218 views
Skip to first unread message

Carmine

unread,
Jan 22, 2017, 10:21:06 AM1/22/17
to masstransit-discuss
Hi,

I'm writing a saga with 7 states and I want to create unit tests in order to test all the stuff.

Do you have any example of this? I studied the source code tests and I've already written some ones but I can't find an easy way to transition the saga state directly in a state that I want to test.

Right now, I'm writing tests like:

            var startCommand = CreateScheduleTenderCommand();
            await InputQueueSendEndpoint.Send(startCommand);

            var foundSagaId = await ShouldContainSaga(startCommand.Email, _saga.State1);
       
         
            await Bus.Publish(new EventA(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State2);

                      await Bus.Publish(new EventB(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State3);

                      await Bus.Publish(new EventC(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State4);

           // -> Ok, now I'm in the state that I want to test, so I write me test code below....



This approach works, but I think that there is another way to do this, right?

Thanks

Chris Patterson

unread,
Jan 22, 2017, 12:51:35 PM1/22/17
to masstrans...@googlegroups.com
You could just create the saga instance matching the correlationId and add it to the in memory repository. But generally I walk the sagas through the events leading up to the subject area for testing as well.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/b8388440-1fe1-41f8-9e36-59347f01010b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carmine

unread,
Apr 5, 2017, 5:42:13 AM4/5/17
to masstransit-discuss
Hi Chris,

I'm having a strange issue. 
I've written an unit test like the one previously posted, but if I run it in debug mode, everything work well instead if I run it without debug, it fails with a timeout error because "_sagaRepository.ShouldContainSaga" method doesn't return a value in TestTimeout timespan.

Do you have any suggestion?
Thanks

On Sunday, January 22, 2017 at 6:51:35 PM UTC+1, Chris Patterson wrote:
You could just create the saga instance matching the correlationId and add it to the in memory repository. But generally I walk the sagas through the events leading up to the subject area for testing as well.

On Sun, Jan 22, 2017 at 7:21 AM, Carmine <carmine...@gmail.com> wrote:
Hi,

I'm writing a saga with 7 states and I want to create unit tests in order to test all the stuff.

Do you have any example of this? I studied the source code tests and I've already written some ones but I can't find an easy way to transition the saga state directly in a state that I want to test.

Right now, I'm writing tests like:

            var startCommand = CreateScheduleTenderCommand();
            await InputQueueSendEndpoint.Send(startCommand);

            var foundSagaId = await ShouldContainSaga(startCommand.Email, _saga.State1);
       
         
            await Bus.Publish(new EventA(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State2);

                      await Bus.Publish(new EventB(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State3);

                      await Bus.Publish(new EventC(instance.ManagementTaskId);
            await ShouldContainSaga(startCommand.TenderEmail, _saga.State4);

           // -> Ok, now I'm in the state that I want to test, so I write me test code below....



This approach works, but I think that there is another way to do this, right?

Thanks

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages