From 0aec652e5f675f88d6b07a97ae5b5a1991da8f34 Mon Sep 17 00:00:00 2001 From: Hrvoje Hudoletnjak Date: Tue, 19 Aug 2014 23:44:42 +0100 Subject: [PATCH] Persistence store commit returns null fix, passing test added. Simulates pipeline pre-commit hook returning a false. --- .../OptimisticEventStreamTests.cs | 23 +++++++++++++++++++ src/NEventStore/OptimisticEventStream.cs | 10 +++++--- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/NEventStore.Tests/OptimisticEventStreamTests.cs b/src/NEventStore.Tests/OptimisticEventStreamTests.cs index 31c3c9cae..463f4f1a8 100644 --- a/src/NEventStore.Tests/OptimisticEventStreamTests.cs +++ b/src/NEventStore.Tests/OptimisticEventStreamTests.cs @@ -524,6 +524,29 @@ public void should_throw_an_exception_when_removing_from_the_uncommitted_collect { Catch.Exception(() => Stream.UncommittedEvents.Remove(null)).Should().BeOfType(); } + } + + public class when_persistance_store_commit_returns_null : on_the_event_stream + { + protected override void Context() + { + // simulates pipeline pre-commit hook returning a false + A.CallTo(() => Persistence.Commit(A.Ignored)).Returns(null); + } + + protected override void Because() + { + Stream = new OptimisticEventStream(BucketId, StreamId, Persistence); + Stream.Add(new EventMessage() { Body = "body" }); + Stream.CommitChanges(Guid.NewGuid()); + } + + [Fact] + public void should_not_contain_commited_events() + { + Stream.CommittedEvents.Count().Should().Be(0); + } + } public abstract class on_the_event_stream : SpecificationBase, IUseFixture diff --git a/src/NEventStore/OptimisticEventStream.cs b/src/NEventStore/OptimisticEventStream.cs index 66d4ed88c..7f8fc6a48 100644 --- a/src/NEventStore/OptimisticEventStream.cs +++ b/src/NEventStore/OptimisticEventStream.cs @@ -186,9 +186,13 @@ private void PersistChanges(Guid commitId) CommitAttempt attempt = BuildCommitAttempt(commitId); Logger.Debug(Resources.PersistingCommit, commitId, StreamId); - ICommit commit = _persistence.Commit(attempt); - - PopulateStream(StreamRevision + 1, attempt.StreamRevision, new[] { commit }); + ICommit commit = _persistence.Commit(attempt); + + if (commit != null) + { + PopulateStream(StreamRevision + 1, attempt.StreamRevision, new[] {commit}); + } + ClearChanges(); }