Skip to content

Commit

Permalink
#3636 Test for Explicit live aggregations should support string strea…
Browse files Browse the repository at this point in the history
…m identities
  • Loading branch information
erdtsieck committed Jan 24, 2025
1 parent bc4e604 commit 7bbe1a0
Showing 1 changed file with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace EventSourcingTests.Projections;

public class using_explicit_code_for_live_aggregation : OneOffConfigurationsContext
{

[Fact]
public async Task using_a_custom_projection_for_live_aggregation()
{
Expand All @@ -35,6 +34,25 @@ public async Task using_a_custom_projection_for_live_aggregation()
aggregate.Id.ShouldBe(streamId);
}

[Fact]
public async Task using_a_custom_projection_for_live_aggregation_that_has_string_as_id()
{
StoreOptions(opts =>
{
opts.Projections.Add(new ExplicitCounterThatHasStringId(), ProjectionLifecycle.Live);
opts.Events.StreamIdentity = StreamIdentity.AsString;
});

var streamId = Guid.NewGuid().ToString();
theSession.Events.StartStream<SimpleAggregateAsString>(streamId, new AEvent(), new AEvent(), new BEvent(), new CEvent(), new CEvent(), new CEvent());
await theSession.SaveChangesAsync();

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

[Fact]
public async Task using_a_custom_projection_for_live_aggregation_with_query_session()
Expand Down Expand Up @@ -96,3 +114,31 @@ public override SimpleAggregate Apply(SimpleAggregate snapshot, IReadOnlyList<IE
}

#endregion

public class ExplicitCounterThatHasStringId: CustomProjection<SimpleAggregateAsString, string>
{
public override SimpleAggregateAsString Apply(SimpleAggregateAsString snapshot, IReadOnlyList<IEvent> events)
{
snapshot ??= new();
foreach (var e in events.Select(x => x.Data))
{
switch (e)
{
case AEvent:
snapshot.ACount++;
break;
case BEvent:
snapshot.BCount++;
break;
case CEvent:
snapshot.CCount++;
break;
case DEvent:
snapshot.DCount++;
break;
}
}

return snapshot;
}
}

0 comments on commit 7bbe1a0

Please sign in to comment.