Skip to content

Commit

Permalink
#3546 Explicit live aggregations should not create tables
Browse files Browse the repository at this point in the history
  • Loading branch information
erdtsieck committed Nov 6, 2024
1 parent 69f1e31 commit 3ec956b
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Marten.Events.Projections;
using Marten.Testing.Harness;
using Shouldly;
using Weasel.Postgresql.Tables;
using Xunit;

namespace EventSourcingTests.Projections;
Expand All @@ -28,8 +29,6 @@ public async Task using_a_custom_projection_for_live_aggregation()
await theSession.SaveChangesAsync();

var aggregate = await theSession.Events.AggregateStreamAsync<SimpleAggregate>(streamId);
theStore.StorageFeatures.AllDocumentMappings.Select(x => x.DocumentType)
.ShouldNotContain(typeof(SimpleAggregate));
aggregate.ACount.ShouldBe(2);
aggregate.BCount.ShouldBe(1);
aggregate.CCount.ShouldBe(3);
Expand All @@ -48,14 +47,32 @@ public async Task using_a_custom_projection_for_live_aggregation_with_query_sess
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();
await 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);
}

[Fact]
public async Task does_not_create_tables()
{
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();
await theStore.Storage.ApplyAllConfiguredChangesToDatabaseAsync();

var eventStream = await theSession.Events.FetchForWriting<SimpleAggregate>(streamId);
await theSession.SaveChangesAsync();
var tables = theStore.Storage.AllObjects().OfType<Table>();
tables.ShouldNotContain(x => x.Identifier.Name.Contains(nameof(SimpleAggregate), StringComparison.OrdinalIgnoreCase));
}
}

#region sample_using_simple_explicit_code_for_live_aggregation
Expand Down

0 comments on commit 3ec956b

Please sign in to comment.