public void ReturnSaveResultIfNoExceptionsThrown() { var saga = new Mock <Saga>(); var pipelineHook = new Mock <PipelineHook>(); var decoratedSagaStore = new Mock <IStoreSagas>(); var sagaStore = new HookableSagaStore(decoratedSagaStore.Object, new[] { pipelineHook.Object }); // ReSharper disable AccessToDisposedClosure using (var context = new SagaContext(typeof(Saga), Guid.NewGuid(), new FakeEvent())) { decoratedSagaStore.Setup(mock => mock.Save(saga.Object, context)).Returns(saga.Object); Assert.Same(saga.Object, sagaStore.Save(saga.Object, context)); } // ReSharper restore AccessToDisposedClosure }
public void InvokePreSaveHooksBeforeDecoratedSave() { var saga = new Mock <Saga>(); var pipelineHook = new Mock <PipelineHook>(); var decoratedSagaStore = new Mock <IStoreSagas>(); var sagaStore = new HookableSagaStore(decoratedSagaStore.Object, new[] { pipelineHook.Object }); // ReSharper disable AccessToDisposedClosure using (var context = new SagaContext(typeof(Saga), Guid.NewGuid(), new FakeEvent())) { pipelineHook.Setup(mock => mock.PreSave(saga.Object, context)).Throws(new InvalidOperationException()); Assert.Throws <InvalidOperationException>(() => sagaStore.Save(saga.Object, context)); decoratedSagaStore.Verify(mock => mock.Save(saga.Object, context), Times.Never()); } // ReSharper restore AccessToDisposedClosure }
public void ReturnSaveResultIfNoExceptionsThrown() { var saga = new Mock<Saga>(); var pipelineHook = new Mock<PipelineHook>(); var decoratedSagaStore = new Mock<IStoreSagas>(); var sagaStore = new HookableSagaStore(decoratedSagaStore.Object, new[] { pipelineHook.Object }); // ReSharper disable AccessToDisposedClosure using (var context = new SagaContext(typeof(Saga), Guid.NewGuid(), new FakeEvent())) { decoratedSagaStore.Setup(mock => mock.Save(saga.Object, context)).Returns(saga.Object); Assert.Same(saga.Object, sagaStore.Save(saga.Object, context)); } // ReSharper restore AccessToDisposedClosure }
public void InvokePostSaveHooksIfDecoratedSaveThrowsException() { var saga = new Mock<Saga>(); var pipelineHook = new Mock<PipelineHook>(); var error = new InvalidOperationException(); var decoratedSagaStore = new Mock<IStoreSagas>(); var sagaStore = new HookableSagaStore(decoratedSagaStore.Object, new[] { pipelineHook.Object }); // ReSharper disable AccessToDisposedClosure using (var context = new SagaContext(typeof(Saga), Guid.NewGuid(), new FakeEvent())) { decoratedSagaStore.Setup(mock => mock.Save(saga.Object, context)).Throws(error); Assert.Throws<InvalidOperationException>(() => sagaStore.Save(saga.Object, context)); pipelineHook.Verify(mock => mock.PostSave(saga.Object, context, error), Times.Once()); } // ReSharper restore AccessToDisposedClosure }