Skip to content

Commit

Permalink
Exit early when appending empty event list (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Lycken committed Nov 7, 2017
1 parent f4a04a6 commit 6b5e0c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using RdbmsEventStore.EntityFramework.Tests.Infrastructure;
using RdbmsEventStore.EntityFramework.Tests.TestData;
using Moq;
using Xunit;


Expand Down Expand Up @@ -34,6 +35,25 @@ public async Task CommittingWithOutOfSyncDataThrowsConflictException()
await Assert.ThrowsAsync<ConflictException>(() => store.Append(stream, 0, new[] { new FooEvent { Foo = "Qux" } }));
}

[Fact]
public async Task CommittingNoEventsExitsEarly() {
var context = new Mock<EventStoreContext<GuidGuidPersistedEvent>>(MockBehavior.Strict);
var set = new Mock<DbSet<GuidGuidPersistedEvent>>(MockBehavior.Strict);
context.Setup(c => c.Set<GuidGuidPersistedEvent>()).Returns(set.Object);
var stream = Guid.NewGuid();

var store = _fixture.BuildEventStore(context.Object);

try {
await store.Append(stream, 0, new object[] { });
} catch (NotImplementedException) {
// Thrown by the mock DbSet if we try to query for existing events
// This indicates that we didn't exit early

Assert.False(true, "Expected to exit early, but apparently didn't.");
}
}

[Fact]
public async Task CommittingMultipleEventsStoresAllEventsInContext()
{
Expand Down Expand Up @@ -77,4 +97,4 @@ public async Task CommittingMultipleEventsIncrementsVersionForEachEvent()
bar => Assert.Equal(2, bar.Version));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Effort.EF6" Version="1.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="tlycken.Extensions" Version="0.5.0" />
<PackageReference Include="Moq" Version="4.7.145" />
<PackageReference Include="xunit" Version="2.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public async Task<IEnumerable<TEvent>> Events(Func<IQueryable<TEventMetadata>, I

public async Task Append(TStreamId streamId, long versionBefore, IEnumerable<object> payloads)
{
if (!payloads.Any()) {
return;
}

using (await _writeLock.Aquire(streamId))
{
var highestVersionNumber = await _context.Events
Expand Down

0 comments on commit 6b5e0c9

Please sign in to comment.