From 839709b32ed3d0598cf63a72ceba8b2f26791d3b Mon Sep 17 00:00:00 2001 From: Joshua Nitschke Date: Fri, 6 Oct 2023 01:08:11 -0700 Subject: [PATCH] added some other variations --- ...inline_projections_should_always_update.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/EventSourcingTests/Bugs/Bug_xxxx_inline_projections_should_always_update.cs b/src/EventSourcingTests/Bugs/Bug_xxxx_inline_projections_should_always_update.cs index fc7e440adb..6b44afb25f 100644 --- a/src/EventSourcingTests/Bugs/Bug_xxxx_inline_projections_should_always_update.cs +++ b/src/EventSourcingTests/Bugs/Bug_xxxx_inline_projections_should_always_update.cs @@ -119,6 +119,65 @@ async Task CreateFromEvents(IEnumerable + { + c.Projections.Add(ProjectionLifecycle.Inline); + }); + + var streamId = Guid.NewGuid(); + var events = new List(); + events.Add(new WeekStarted(streamId)); + events.Add(new ApplesBought(streamId, 1)); + events.Add(new BananasBought(streamId, 8)); + + var weekDetails = await CreateFromEvents(events.ToArray()); + weekDetails.ShouldNotBeNull(); + weekDetails.Apples.ShouldBe(1); + weekDetails.Bananas.ShouldBe(8); + + async Task CreateFromEvents(TEvent[] events) + where TEvent : IAggregateStreamEvent + where TAggregate : class + { + if (!events.Any()) throw new InvalidOperationException("Must have at least one event"); + var id = events.First().Id; + await using var session = theStore.LightweightSession(); + session.Events.StartStream(id, events); + await session.SaveChangesAsync(); + return await session.LoadAsync(id) ?? throw new Exception("Should not be null)"); + } + } + + [Fact] + public async Task projection_updates_with_save_strategy_variation_1c_generics_version() + { + StoreOptions(c => + { + c.Projections.Add(ProjectionLifecycle.Inline); + }); + + var streamId = Guid.NewGuid(); + var weekDetails = await CreateFromEvents(new WeekStarted(streamId), new ApplesBought(streamId, 1), new BananasBought(streamId, 8)); + weekDetails.ShouldNotBeNull(); + weekDetails.Apples.ShouldBe(1); + weekDetails.Bananas.ShouldBe(8); + + async Task CreateFromEvents(params TEvent[] events) + where TEvent : IAggregateStreamEvent + where TAggregate : class + { + if (!events.Any()) throw new InvalidOperationException("Must have at least one event"); + var id = events.First().Id; + await using var session = theStore.LightweightSession(); + session.Events.StartStream(id, events); + await session.SaveChangesAsync(); + return await session.LoadAsync(id) ?? throw new Exception("Should not be null)"); + } + } + [Fact] public async Task projection_updates_with_save_strategy_variation_2_generics_version() {