Skip to content

Commit

Permalink
Issue: #4 added a test to show what happens when doing multiple commi…
Browse files Browse the repository at this point in the history
…ts with the same BucketId / StreamId / CommitId combination
  • Loading branch information
AGiorgetti committed Dec 15, 2015
1 parent f953b7c commit 5e1f674
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using NEventStore.Persistence.AcceptanceTests.BDD;
using Xunit;
using Xunit.Should;

public abstract class using_a_configured_repository : SpecificationBase
{
protected IRepository _repository;
Expand Down Expand Up @@ -155,6 +155,55 @@ public void should_be_returned_when_loaded_by_id()
}
}

/// <summary>
/// Idempotency Check:
/// Internally a DuplicateCommitException will be raised and catch by the repository,
/// the whole commit will be discarded, we assume the it's the same commit issued twice.
///
/// Issue: #4
/// </summary>
public class when_an_aggregate_is_persisted_using_the_same_commitId_twice : using_a_configured_repository
{
private TestAggregate _testAggregate;

private Guid _id;

protected override void Context()
{
base.Context();
_id = Guid.NewGuid();
_testAggregate = new TestAggregate(_id, "Test");
}

protected override void Because()
{
var commitId = Guid.NewGuid();
_repository.Save(_testAggregate, commitId, null);

_testAggregate.ChangeName("one");

_repository.Save(_testAggregate, commitId);
}

[Fact]
public void the_second_commit_was_silently_discarded_and_not_written_to_database()
{
var aggregate = _repository.GetById<TestAggregate>(_id);
aggregate.Name.ShouldBe("Test");
aggregate.Version.ShouldBe(1);
}

[Fact]
public void the_aggregate_still_has_pending_changes()
{
var uncommittedEvents = ((IAggregate)_testAggregate).GetUncommittedEvents();
uncommittedEvents.ShouldNotBeEmpty();
var enumerator = uncommittedEvents.GetEnumerator();
enumerator.MoveNext();
enumerator.Current.ShouldBeInstanceOf<NameChangedEvent>();
}
}

public class when_an_aggregate_is_persisted_by_two_repositories : SpecificationBase
{
protected IRepository _repository1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public void Save(string bucketId, IAggregate aggregate, Guid commitId, Action<ID
catch (DuplicateCommitException)
{
stream.ClearChanges();
return;
// Issue: #4 and test: when_an_aggregate_is_persisted_using_the_same_commitId_twice
// should we rethtow the exception here? or provide a feedback whether the save was successful ?
return;
}
catch (ConcurrencyException e)
{
Expand Down

0 comments on commit 5e1f674

Please sign in to comment.