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()); }
protected UsingSagaEventHandlerBase() { var sagaMetadata = new FakeSaga().GetMetadata(); var commandPublisher = new Mock <IPublishCommands>(); var executor = new Action <Object, Event>((handler, e) => { ((FakeSaga)handler).Handle((Timeout)e); Handled = true; }); var eventHandler = new EventHandler(typeof(FakeSaga), typeof(Timeout), executor, () => { throw new NotSupportedException(); }); SystemTime.ClearOverride(); SagaEventHandler = new SagaTimeoutHandler(eventHandler, sagaMetadata, SagaStore.Object, new Lazy <IPublishCommands>(() => commandPublisher.Object)); }
protected UsingSagaEventHandlerBase() { var sagaMetadata = new FakeSaga().GetMetadata(); var commandPublisher = new Mock<IPublishCommands>(); var executor = new Action<Object, Event>((handler, e) => { ((FakeSaga)handler).Handle((Timeout)e); Handled = true; }); var eventHandler = new EventHandler(typeof(FakeSaga), typeof(Timeout), executor, () => { throw new NotSupportedException(); }); SystemTime.ClearOverride(); SagaEventHandler = new SagaTimeoutHandler(eventHandler, sagaMetadata, SagaStore.Object, new Lazy<IPublishCommands>(() => commandPublisher.Object)); }
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()); }
protected UsingSagaEventHandlerBase() { var executor = new Action<Object, Event>((handler, e) => { ((FakeSaga)handler).Handle((FakeEvent)e); Handled = true; }); SagaId = GuidStrategy.NewGuid(); AggregateId = GuidStrategy.NewGuid(); Event = new FakeEvent { Id = SagaId }; SagaMetadata = new FakeSaga().GetMetadata(); EventContext = new EventContext(AggregateId, HeaderCollection.Empty, Event); EventHandler = new EventHandler(typeof(FakeSaga), typeof(FakeEvent), executor, () => { throw new NotSupportedException(); }); SagaEventHandler = new SagaEventHandler(EventHandler, SagaMetadata, SagaStore.Object, new Lazy<IPublishCommands>(() => CommandPublisher.Object)); }
protected UsingSagaEventHandlerBase() { var executor = new Action <Object, Event>((handler, e) => { ((FakeSaga)handler).Handle((FakeEvent)e); Handled = true; }); SagaId = GuidStrategy.NewGuid(); AggregateId = GuidStrategy.NewGuid(); Event = new FakeEvent { Id = SagaId }; SagaMetadata = new FakeSaga().GetMetadata(); EventContext = new EventContext(AggregateId, HeaderCollection.Empty, Event); EventHandler = new EventHandler(typeof(FakeSaga), typeof(FakeEvent), executor, () => { throw new NotSupportedException(); }); SagaEventHandler = new SagaEventHandler(EventHandler, SagaMetadata, SagaStore.Object, new Lazy <IPublishCommands>(() => CommandPublisher.Object)); }
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()); }