public void SetAsProcessed_should_throw_ArgumentException_if_message_correlation_id_invalid() { var sut = new DummySagaState(Guid.NewGuid()); var message = StartDummySaga.New(); Assert.Throws <ArgumentException>(() => sut.SetAsProcessed(message)); }
public void CheckWasProcessed_should_return_true_if_message_processed() { var sut = new DummySagaState(Guid.NewGuid()); var message = new StartDummySaga(Guid.NewGuid(), sut.Id); sut.SetAsProcessed(message); sut.CheckWasProcessed(message).Should().BeTrue(); }
public async Task RunAsync_should_not_execute_handler_if_message_already_processed() { 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.SetAsProcessed(message); 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>()); }
public void SetAsProcessed_should_throw_ArgumentNullException_if_message_null() { var sut = new DummySagaState(Guid.NewGuid()); Assert.Throws <ArgumentNullException>(() => sut.SetAsProcessed((IMessage)null)); }