-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Separate the concepts of an event, and the storage type for it * Rename Commit->Append * Increment version; breaking changes
- Loading branch information
Tomas Lycken
committed
Oct 25, 2017
1 parent
ec63c4a
commit c8feaac
Showing
36 changed files
with
487 additions
and
284 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mode: ContinuousDelivery | ||
next-version: 0.3.0 | ||
next-version: 0.4.0 | ||
branches: | ||
master: | ||
tag: beta | ||
|
114 changes: 114 additions & 0 deletions
114
src/RdbmsEventStore.EntityFramework.Tests/EventStoreTests/ExtraMetaTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using RdbmsEventStore.EntityFramework.Tests.Infrastructure; | ||
using RdbmsEventStore.EntityFramework.Tests.TestData; | ||
using RdbmsEventStore.EventRegistry; | ||
using RdbmsEventStore.Serialization; | ||
using Xunit; | ||
|
||
namespace RdbmsEventStore.EntityFramework.Tests.EventStoreTests | ||
{ | ||
[Collection(nameof(InMemoryDatabaseCollection))] | ||
public class ExtraMetaTests : IClassFixture<ExtraMetaEventFactoryFixture> | ||
{ | ||
private readonly ExtraMetaEventFactoryFixture _fixture; | ||
private readonly EventStoreContext<ExtraMetaLongStringPersistedEventMetadata> _dbContext; | ||
|
||
// ReSharper disable once UnusedParameter.Local | ||
public ExtraMetaTests(ExtraMetaEventFactoryFixture fixture, AssemblyInitializerFixture _) | ||
{ | ||
EffortProviderFactory.ResetDb(); | ||
_fixture = fixture; | ||
_dbContext = new EventStoreContext<ExtraMetaLongStringPersistedEventMetadata>(); | ||
|
||
var stream1 = _fixture.EventFactory.Create("stream-1", 0, new object[] { | ||
new FooEvent { Foo = "Foo" }, | ||
new BarEvent { Bar = "Bar" }, | ||
new FooEvent { Foo = "Baz" } | ||
}) | ||
.Select(_fixture.EventSerializer.Serialize); | ||
var stream2 = _fixture.EventFactory.Create("stream-2", 0, new object[] { | ||
new FooEvent { Foo = "Boo" }, | ||
new BarEvent { Bar = "Far" } | ||
}) | ||
.Select(_fixture.EventSerializer.Serialize); | ||
|
||
_dbContext.Events.AddRange(stream1); | ||
_dbContext.Events.AddRange(stream2); | ||
_dbContext.SaveChanges(); | ||
} | ||
|
||
[Theory] | ||
[InlineData("stream-1", 3)] | ||
[InlineData("stream-2", 2)] | ||
public async Task ReturnsEventsFromCorrectStreamOnly(string streamId, long expectedCount) | ||
{ | ||
var store = _fixture.BuildEventStore(_dbContext) as IEventStream<string, ExtraMetaStringEvent, IExtraMeta>; | ||
var events = await store.Events(streamId); | ||
Assert.Equal(expectedCount, events.Count()); | ||
} | ||
|
||
[Theory] | ||
[InlineData("stream-1", 2)] | ||
[InlineData("stream-2", 1)] | ||
public async Task ReturnsEventsAccordingToQuery(string streamId, long expectedCount) | ||
{ | ||
var store = _fixture.BuildEventStore(_dbContext) as IEventStream<string, ExtraMetaStringEvent, IExtraMeta>; | ||
var events = await store.Events(streamId, es => es.Where(e => e.ExtraMeta.StartsWith("Foo"))); | ||
Assert.Equal(expectedCount, events.Count()); | ||
} | ||
|
||
[Theory] | ||
[InlineData("stream-1", 2)] | ||
[InlineData("stream-2", 1)] | ||
public async Task ReturnsEventsWithMetadata(string streamId, long expectedCount) | ||
{ | ||
var store = _fixture.BuildEventStore(_dbContext) as IEventStream<string, ExtraMetaStringEvent, IExtraMeta>; | ||
var events = await store.Events(streamId, es => es.Where(e => e.ExtraMeta.StartsWith("Foo"))); | ||
Assert.All(events, @event => Assert.StartsWith("Foo", @event.ExtraMeta)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("stream-1", 2)] | ||
[InlineData("stream-2", 1)] | ||
public async Task CanQueryByExtraMetadata(string streamId, long expectedCount) | ||
{ | ||
var store = _fixture.BuildEventStore(_dbContext) as IEventStream<string, ExtraMetaStringEvent, IExtraMeta>; | ||
var events = await store.Events(streamId, es => es.Where(e => e.ExtraMeta.StartsWith("Foo"))); | ||
Assert.Equal(expectedCount, events.Count()); | ||
} | ||
} | ||
|
||
public class ExtraMetaEventFactory : DefaultEventFactory<string, ExtraMetaStringEvent> | ||
{ | ||
private int _total; | ||
|
||
protected override ExtraMetaStringEvent CreateSingle(string streamId, long version, object payload) | ||
{ | ||
var @event = base.CreateSingle(streamId, version, payload); | ||
@event.ExtraMeta = $"{payload.GetType().Name}-{_total++}"; | ||
return @event; | ||
} | ||
} | ||
|
||
public class ExtraMetaEventSerializer : DefaultEventSerializer<string, ExtraMetaStringEvent, ExtraMetaLongStringPersistedEventMetadata> | ||
{ | ||
public ExtraMetaEventSerializer(IEventRegistry registry) : base(registry) | ||
{ | ||
} | ||
|
||
public override ExtraMetaLongStringPersistedEventMetadata Serialize(ExtraMetaStringEvent @event) | ||
{ | ||
var serialized = base.Serialize(@event); | ||
serialized.ExtraMeta = @event.ExtraMeta; | ||
return serialized; | ||
} | ||
|
||
public override ExtraMetaStringEvent Deserialize(ExtraMetaLongStringPersistedEventMetadata @event) | ||
{ | ||
var deserialized = base.Deserialize(@event); | ||
deserialized.ExtraMeta = @event.ExtraMeta; | ||
return deserialized; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 25 additions & 11 deletions
36
src/RdbmsEventStore.EntityFramework.Tests/Infrastructure/EventStoreFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,43 @@ | ||
using System; | ||
using System.Data.Entity; | ||
using RdbmsEventStore.EntityFramework.Tests.EventStoreTests; | ||
using RdbmsEventStore.EntityFramework.Tests.TestData; | ||
using RdbmsEventStore.EventRegistry; | ||
using RdbmsEventStore.Serialization; | ||
|
||
namespace RdbmsEventStore.EntityFramework.Tests.Infrastructure | ||
{ | ||
public class EventStoreFixture<TId, TStreamId, TEvent> | ||
public class EventStoreFixture<TId, TStreamId, TEvent, TEventMetadata, TPersistedEvent> | ||
where TId : IEquatable<TId> | ||
where TStreamId : IEquatable<TStreamId> | ||
where TEvent : class, IMutableEvent<TId, TStreamId>, new() | ||
where TEvent : class, TEventMetadata, IMutableEvent<TStreamId>, new() | ||
where TPersistedEvent : class, TEventMetadata, IPersistedEvent<TStreamId>, new() | ||
where TEventMetadata : IEventMetadata<TStreamId> | ||
{ | ||
public EventStoreFixture() | ||
{ | ||
EventRegistry = new AssemblyEventRegistry(typeof(TEvent), type => type.Name, type => !type.Name.StartsWith("<>")); | ||
EventSerializer = new DefaultEventSerializer(); | ||
EventFactory = new DefaultEventFactory<TId, TStreamId, TEvent>(EventRegistry, EventSerializer); | ||
EventSerializer = new DefaultEventSerializer<TStreamId, TEvent, TPersistedEvent>(EventRegistry); | ||
EventFactory = new DefaultEventFactory<TStreamId, TEvent>(); | ||
WriteLock = new WriteLock(); | ||
} | ||
|
||
public IEventRegistry EventRegistry { get; } | ||
public IEventSerializer EventSerializer { get; } | ||
public DefaultEventFactory<TId, TStreamId, TEvent> EventFactory { get; } | ||
public IWriteLock WriteLock { get; } | ||
public IEventRegistry EventRegistry { get; protected set; } | ||
public IEventSerializer<TEvent, TPersistedEvent> EventSerializer { get; protected set; } | ||
public IEventFactory<TStreamId, TEvent> EventFactory { get; protected set; } | ||
public IWriteLock WriteLock { get; protected set; } | ||
|
||
public EntityFrameworkEventStore<TId, TStreamId, TEventStoreContext, TEvent> BuildEventStore<TEventStoreContext>(TEventStoreContext dbContext) | ||
where TEventStoreContext : DbContext, IEventDbContext<TEvent> | ||
=> new EntityFrameworkEventStore<TId, TStreamId, TEventStoreContext, TEvent>(dbContext, EventFactory, WriteLock); | ||
public EntityFrameworkEventStore<TId, TStreamId, TEventStoreContext, TEvent, TEventMetadata, TPersistedEvent> BuildEventStore<TEventStoreContext>(TEventStoreContext dbContext) | ||
where TEventStoreContext : DbContext, IEventDbContext<TPersistedEvent> | ||
=> new EntityFrameworkEventStore<TId, TStreamId, TEventStoreContext, TEvent, TEventMetadata, TPersistedEvent>(dbContext, EventFactory, WriteLock, EventSerializer); | ||
} | ||
|
||
public class ExtraMetaEventFactoryFixture : EventStoreFixture<long, string, ExtraMetaStringEvent, IExtraMeta, ExtraMetaLongStringPersistedEventMetadata> | ||
{ | ||
public ExtraMetaEventFactoryFixture() | ||
{ | ||
EventFactory = new ExtraMetaEventFactory(); | ||
EventSerializer = new ExtraMetaEventSerializer(EventRegistry); | ||
} | ||
} | ||
} |
Oops, something went wrong.