-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at un-optimized FetchLatest() API
- Loading branch information
1 parent
6940b71
commit 6963782
Showing
8 changed files
with
594 additions
and
0 deletions.
There are no files selected for viewing
161 changes: 161 additions & 0 deletions
161
src/EventSourcingTests/FetchForWriting/fetch_latest_async_aggregate.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,161 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using EventSourcingTests.Aggregation; | ||
using Marten.Events; | ||
using Marten.Events.Projections; | ||
using Marten.Testing.Harness; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace EventSourcingTests.FetchForWriting; | ||
|
||
public class fetch_latest_async_aggregate: OneOffConfigurationsContext | ||
{ | ||
[Fact] | ||
public async Task from_no_current_activity_guid_centric() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregate>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task from_no_current_activity_string_centric() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Async); | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_guid_centric_brand_new() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
|
||
var stream = await theSession.Events.FetchForWriting<SimpleAggregate>(streamId); | ||
stream.AppendMany(new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
await theSession.SaveChangesAsync(); | ||
|
||
var aggregate = await theSession.Events.FetchLatest<SimpleAggregate>(streamId); | ||
aggregate.ACount.ShouldBe(1); | ||
aggregate.BCount.ShouldBe(2); | ||
aggregate.CCount.ShouldBe(3); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_guid_centric_brand_existing() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
using var session = theStore.LightweightSession(); | ||
var stream = await session.Events.FetchForWriting<SimpleAggregate>(streamId); | ||
stream.AppendMany(new DEvent(), new DEvent()); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregate>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
document.DCount.ShouldBe(2); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_string_centric_brand_new() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Async); | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
|
||
var stream = await theSession.Events.FetchForWriting<SimpleAggregateAsString>(streamId); | ||
stream.AppendMany(new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
await theSession.SaveChangesAsync(); | ||
|
||
var aggregate = await theSession.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
aggregate.ACount.ShouldBe(1); | ||
aggregate.BCount.ShouldBe(2); | ||
aggregate.CCount.ShouldBe(3); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_string_centric_existing() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Async); | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
using var session = theStore.LightweightSession(); | ||
var stream = await session.Events.FetchForWriting<SimpleAggregateAsString>(streamId); | ||
stream.AppendMany(new DEvent(), new DEvent()); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
document.DCount.ShouldBe(2); | ||
} | ||
|
||
} |
161 changes: 161 additions & 0 deletions
161
src/EventSourcingTests/FetchForWriting/fetch_latest_inline_aggregate.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,161 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using EventSourcingTests.Aggregation; | ||
using Marten.Events; | ||
using Marten.Events.Projections; | ||
using Marten.Testing.Harness; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace EventSourcingTests.FetchForWriting; | ||
|
||
public class fetch_latest_inline_aggregate: OneOffConfigurationsContext | ||
{ | ||
[Fact] | ||
public async Task from_no_current_activity_guid_centric() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Inline); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregate>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task from_no_current_activity_string_centric() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Inline); | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_guid_centric_brand_new() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Inline); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
|
||
var stream = await theSession.Events.FetchForWriting<SimpleAggregate>(streamId); | ||
stream.AppendMany(new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
await theSession.SaveChangesAsync(); | ||
|
||
var aggregate = await theSession.Events.FetchLatest<SimpleAggregate>(streamId); | ||
aggregate.ACount.ShouldBe(1); | ||
aggregate.BCount.ShouldBe(2); | ||
aggregate.CCount.ShouldBe(3); | ||
} | ||
|
||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_guid_centric_brand_existing() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Inline); | ||
}); | ||
|
||
var streamId = Guid.NewGuid(); | ||
theSession.Events.StartStream<SimpleAggregate>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
using var session = theStore.LightweightSession(); | ||
var stream = await session.Events.FetchForWriting<SimpleAggregate>(streamId); | ||
stream.AppendMany(new DEvent(), new DEvent()); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregate>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
document.DCount.ShouldBe(2); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_string_centric_brand_new() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Inline); | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
|
||
var stream = await theSession.Events.FetchForWriting<SimpleAggregateAsString>(streamId); | ||
stream.AppendMany(new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
await theSession.SaveChangesAsync(); | ||
|
||
var aggregate = await theSession.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
aggregate.ACount.ShouldBe(1); | ||
aggregate.BCount.ShouldBe(2); | ||
aggregate.CCount.ShouldBe(3); | ||
} | ||
|
||
[Fact] | ||
public async Task from_after_fetch_for_writing_string_centric_existing() | ||
{ | ||
StoreOptions(opts => | ||
{ | ||
opts.Events.StreamIdentity = StreamIdentity.AsString; | ||
opts.Projections.Snapshot<SimpleAggregateAsString>(SnapshotLifecycle.Inline); | ||
}); | ||
|
||
var streamId = Guid.NewGuid().ToString(); | ||
theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new BEvent(), new BEvent(), new CEvent(), | ||
new CEvent(), new CEvent()); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
using var session = theStore.LightweightSession(); | ||
var stream = await session.Events.FetchForWriting<SimpleAggregateAsString>(streamId); | ||
stream.AppendMany(new DEvent(), new DEvent()); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var query = theStore.LightweightSession(); | ||
var document = await query.Events.FetchLatest<SimpleAggregateAsString>(streamId); | ||
|
||
document.ACount.ShouldBe(1); | ||
document.BCount.ShouldBe(2); | ||
document.CCount.ShouldBe(3); | ||
document.DCount.ShouldBe(2); | ||
} | ||
|
||
} |
Oops, something went wrong.