diff --git a/src/NEventStore.Domain.Tests/Persistence/IAggregatePersistenceTests.cs b/src/NEventStore.Domain.Tests/Persistence/IAggregatePersistenceTests.cs
index 84352cb..03f6539 100644
--- a/src/NEventStore.Domain.Tests/Persistence/IAggregatePersistenceTests.cs
+++ b/src/NEventStore.Domain.Tests/Persistence/IAggregatePersistenceTests.cs
@@ -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;
@@ -155,6 +155,55 @@ public void should_be_returned_when_loaded_by_id()
}
}
+ ///
+ /// 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
+ ///
+ 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(_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();
+ }
+ }
+
public class when_an_aggregate_is_persisted_by_two_repositories : SpecificationBase
{
protected IRepository _repository1;
diff --git a/src/NEventStore.Domain/Persistence/EventStore/EventStoreRepository.cs b/src/NEventStore.Domain/Persistence/EventStore/EventStoreRepository.cs
index 1e78f07..7e15a74 100644
--- a/src/NEventStore.Domain/Persistence/EventStore/EventStoreRepository.cs
+++ b/src/NEventStore.Domain/Persistence/EventStore/EventStoreRepository.cs
@@ -81,7 +81,9 @@ public void Save(string bucketId, IAggregate aggregate, Guid commitId, Action