public void PublishCommandsOnSuccessfulSave()
            {
                SagaStore.Setup(mock => mock.CreateSaga(typeof(FakeSaga), SagaId)).Returns(new FakeSaga());

                SagaEventHandler.Handle(EventContext);

                CommandPublisher.Verify(mock => mock.Publish(HeaderCollection.Empty, It.IsAny <CommandEnvelope>()), Times.Once());
            }
            public void CommandsNotPublishedOnFailedSave()
            {
                var saga = new FakeSaga();

                SagaStore.Setup(mock => mock.CreateSaga(typeof(FakeSaga), SagaId)).Returns(saga);
                SagaStore.Setup(mock => mock.Save(saga, It.IsAny <SagaContext>())).Throws(new Exception());

                Assert.Throws <Exception>(() => SagaEventHandler.Handle(EventContext));

                CommandPublisher.Verify(mock => mock.Publish(HeaderCollection.Empty, It.IsAny <CommandEnvelope>()), Times.Never());
            }
            public void IgnoreTimeoutIfTimeoutDoesNotMatchScheduled()
            {
                var timeout = SystemTime.Now.Subtract(TimeSpan.FromSeconds(1));
                var saga    = ConfigureSagaTimeout(timeout);

                using (var eventContext = CreateEventContext(saga, SystemTime.Now))
                {
                    SagaEventHandler.Handle(eventContext);

                    SagaStore.Verify(mock => mock.Save(saga, It.Is((SagaContext context) => !context.TimeoutChanged)), Times.Once);
                }

                Assert.Equal(timeout, saga.Timeout);
                Assert.False(Handled);
            }
            public void IgnoreTimeoutIfNoTimeoutScheduled()
            {
                var timeout = SystemTime.Now;
                var saga    = ConfigureSagaTimeout(default(DateTime?));

                using (var eventContext = CreateEventContext(saga, timeout))
                {
                    SagaEventHandler.Handle(eventContext);

                    SagaStore.Verify(mock => mock.Save(saga, It.Is((SagaContext context) => !context.TimeoutChanged)), Times.Once);
                }

                Assert.Null(saga.Timeout);
                Assert.False(Handled);
            }
            public void ClearTimeoutIfTimeoutScheduledAndMatchesExpectedTimeout()
            {
                var timeout = SystemTime.Now;
                var saga    = ConfigureSagaTimeout(timeout);

                using (var eventContext = CreateEventContext(saga, timeout))
                {
                    SagaEventHandler.Handle(eventContext);

                    SagaStore.Verify(mock => mock.Save(saga, It.Is((SagaContext context) => context.TimeoutChanged)), Times.Once);
                }

                Assert.Null(saga.Timeout);
                Assert.True(Handled);
            }
            public void SagaIdExtractedFromEventConfiguration()
            {
                SagaEventHandler.Handle(EventContext);

                SagaStore.Verify(mock => mock.CreateSaga(typeof(FakeSaga), SagaId), Times.Once());
            }