Skip to content

Commit

Permalink
Fix for the problem with using QuerySession + custom projection + agg…
Browse files Browse the repository at this point in the history
…regate stream
  • Loading branch information
jeremydmiller committed Nov 4, 2024
1 parent 72f49d4 commit 6c9c02b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ public async Task using_a_custom_projection_for_live_aggregation()
aggregate.CCount.ShouldBe(3);
aggregate.Id.ShouldBe(streamId);
}

[Fact]
public async Task using_a_custom_projection_for_live_aggregation_with_query_session()
{
StoreOptions(opts =>
{
opts.Projections.Add(new ExplicitCounter(), ProjectionLifecycle.Live);
});

var streamId = theSession.Events.StartStream<SimpleAggregate>(new AEvent(), new AEvent(), new BEvent(), new CEvent(), new CEvent(), new CEvent()).Id;
await theSession.SaveChangesAsync();

using var query = theStore.QuerySession();

var aggregate = await query.Events.AggregateStreamAsync<SimpleAggregate>(streamId);
aggregate.ACount.ShouldBe(2);
aggregate.BCount.ShouldBe(1);
aggregate.CCount.ShouldBe(3);
aggregate.Id.ShouldBe(streamId);
}
}

#region sample_using_simple_explicit_code_for_live_aggregation
Expand Down
2 changes: 1 addition & 1 deletion src/Marten/Events/Aggregation/CustomProjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ async ValueTask<TDoc> ILiveAggregator<TDoc>.BuildAsync(IReadOnlyList<IEvent> eve
{
if (!events.Any()) return default;

var documentSessionBase = session.As<DocumentSessionBase>();
var documentSessionBase = session as DocumentSessionBase ?? (DocumentSessionBase)session.DocumentStore.LightweightSession();

var slice = new EventSlice<TDoc, TId>(default, session, events);
await ApplyChangesAsync(documentSessionBase, slice, cancellation).ConfigureAwait(false);
Expand Down

0 comments on commit 6c9c02b

Please sign in to comment.