Esempio n. 1
0
        public void IsCompleted_should_return_true_after_state_is_marked_as_completed()
        {
            var state = new DummySagaState(Guid.NewGuid());

            state.MarkAsCompleted();
            state.IsCompleted().Should().BeTrue();
        }
Esempio n. 2
0
        public async Task RunAsync_should_not_execute_handler_if_saga_is_marked_as_completed()
        {
            var message        = new StartDummySaga(Guid.NewGuid(), Guid.NewGuid());
            var messageContext = NSubstitute.Substitute.For <IMessageContext <StartDummySaga> >();

            messageContext.Message.Returns(message);

            var state = new DummySagaState(message.CorrelationId);

            state.MarkAsCompleted();

            var saga = NSubstitute.Substitute.ForPartsOf <DummySaga>(state);

            saga.When(s => s.HandleAsync(Arg.Any <IMessageContext <StartDummySaga> >(), Arg.Any <CancellationToken>()))
            .DoNotCallBase();

            var sagaFactory = NSubstitute.Substitute.For <ISagaFactory <DummySaga, DummySagaState> >();

            sagaFactory.Create(state)
            .Returns(saga);

            var sagaStateService = NSubstitute.Substitute.For <ISagaStateService <DummySaga, DummySagaState> >();

            sagaStateService.GetAsync(messageContext, Arg.Any <CancellationToken>())
            .Returns((state, Guid.NewGuid()));

            var logger = NSubstitute.Substitute.For <ILogger <SagaRunner <DummySaga, DummySagaState> > >();

            var transactionManager = NSubstitute.Substitute.For <ITransactionManager>();
            var policyFactory      = NSubstitute.Substitute.For <ISagaPolicyFactory <DummySaga> >();

            var sut = new SagaRunner <DummySaga, DummySagaState>(sagaFactory, sagaStateService, transactionManager, policyFactory, logger);

            await sut.RunAsync(messageContext, CancellationToken.None);

            sagaFactory.DidNotReceiveWithAnyArgs().Create(null);

            await saga.DidNotReceiveWithAnyArgs()
            .HandleAsync(messageContext, Arg.Any <CancellationToken>());
        }