Skip to content

Commit

Permalink
Merge pull request NEventStore#368 from hudo/pipelinehook-issue
Browse files Browse the repository at this point in the history
Persistence store commit returns null fix, passing test added.
  • Loading branch information
damianh committed Sep 7, 2014
2 parents 3a1ac71 + 0aec652 commit c9cfad6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
23 changes: 23 additions & 0 deletions src/NEventStore.Tests/OptimisticEventStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,29 @@ public void should_throw_an_exception_when_removing_from_the_uncommitted_collect
{
Catch.Exception(() => Stream.UncommittedEvents.Remove(null)).Should().BeOfType<NotSupportedException>();
}
}

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<CommitAttempt>.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<FakeTimeFixture>
Expand Down
10 changes: 7 additions & 3 deletions src/NEventStore/OptimisticEventStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit c9cfad6

Please sign in to comment.