From 1206d8e7d22c49bffa42f5a623b3e07b77b861e5 Mon Sep 17 00:00:00 2001 From: "Jeremy D. Miller" Date: Mon, 22 Jul 2024 07:06:01 -0500 Subject: [PATCH] Adding more tests on revision setting of aggregates after quick append + Inline. Closes GH-3314 --- .../fetching_inline_aggregates_for_writing.cs | 56 +++++++++++++++++++ .../fetching_live_aggregates_for_writing.cs | 53 ++++++++++++------ 2 files changed, 91 insertions(+), 18 deletions(-) diff --git a/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs b/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs index db459ee276..8f6c1b158e 100644 --- a/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs +++ b/src/EventSourcingTests/Aggregation/fetching_inline_aggregates_for_writing.cs @@ -37,6 +37,62 @@ public async Task fetch_new_stream_for_writing_Guid_identifier() document.CCount.ShouldBe(2); } + [Fact] + public async Task revision_is_updated_after_quick_appending_with_IRevisioned() + { + StoreOptions(opts => + { + opts.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.Events.AppendMode = EventAppendMode.Quick; + opts.Events.UseIdentityMapForInlineAggregates = true; + }); + + var streamId = Guid.NewGuid(); + + var stream = await theSession.Events.FetchForWriting(streamId); + stream.Aggregate.ShouldBeNull(); + stream.CurrentVersion.ShouldBe(0); + + stream.AppendOne(new AEvent()); + stream.AppendMany(new BEvent(), new BEvent(), new BEvent()); + stream.AppendMany(new CEvent(), new CEvent()); + + await theSession.SaveChangesAsync(); + + var document = await theSession.LoadAsync(streamId); + document.Version.ShouldBe(6); + } + + [Fact] + public async Task revision_is_updated_after_quick_appending_with_custom_mapped_version() + { + StoreOptions(opts => + { + opts.Projections.Snapshot(SnapshotLifecycle.Inline).Metadata(m => + { + m.Revision.MapTo(x => x.Version); + }); + + opts.Events.AppendMode = EventAppendMode.Quick; + opts.Events.UseIdentityMapForInlineAggregates = true; + }); + + var streamId = Guid.NewGuid(); + + var stream = await theSession.Events.FetchForWriting(streamId); + stream.Aggregate.ShouldBeNull(); + stream.CurrentVersion.ShouldBe(0); + + stream.AppendOne(new AEvent()); + stream.AppendMany(new BEvent(), new BEvent(), new BEvent()); + stream.AppendMany(new CEvent(), new CEvent()); + + await theSession.SaveChangesAsync(); + + var document = await theSession.LoadAsync(streamId); + document.Version.ShouldBe(6); + } + [Fact] public async Task fetch_new_stream_for_writing_Guid_identifier_exception_handling() { diff --git a/src/EventSourcingTests/Aggregation/fetching_live_aggregates_for_writing.cs b/src/EventSourcingTests/Aggregation/fetching_live_aggregates_for_writing.cs index ca6a79d549..aee701a111 100644 --- a/src/EventSourcingTests/Aggregation/fetching_live_aggregates_for_writing.cs +++ b/src/EventSourcingTests/Aggregation/fetching_live_aggregates_for_writing.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using Marten.Events; using Marten.Exceptions; +using Marten.Metadata; using Marten.Testing.Harness; using Shouldly; using Xunit; @@ -344,36 +345,52 @@ await Should.ThrowAsync(async () => }); } +} +public class SimpleAggregate : IRevisioned +{ + // This will be the aggregate version + public int Version { get; set; } + public Guid Id { get; set; } - /* TODO on Tuesday - 1. Happy path append to existing stream - 2. Sad path append to existing stream w/ optimistic concurrency check - 3. Happy path while providing version - 4. Sad path quickly while providing version - 5. Sad path while providing version between starting and committing - - 6. Switch to Inline! - - - - - - + public int ACount { get; set; } + public int BCount { get; set; } + public int CCount { get; set; } + public int DCount { get; set; } + public int ECount { get; set; } + public void Apply(AEvent _) + { + ACount++; + } + public void Apply(BEvent _) + { + BCount++; + } + public void Apply(CEvent _) + { + CCount++; + } - */ + public void Apply(DEvent _) + { + DCount++; + } + public void Apply(EEvent _) + { + ECount++; + } } -public class SimpleAggregate + +public class SimpleAggregate2 { // This will be the aggregate version - public long Version { get; set; } - + public int Version { get; set; } public Guid Id { get; set; }