Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,29 @@ namespace EventSourcingTests.Aggregation;
// Marker interface for the ancillary store that holds reference products
public interface IProductStore : IDocumentStore;

public class ancillary_store_enrichment_tests : IAsyncLifetime
public class ancillary_store_enrichment_tests : HostedStoreContext
{
private IHost _host = null!;
private IDocumentStore _primaryStore = null!;

public async ValueTask InitializeAsync()
public override async ValueTask InitializeAsync()
{
_host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
_host = await StartHostAsync(
opts => opts.Projections.Add<OrderProjection>(ProjectionLifecycle.Async),
configureMarten: marten => marten.ApplyAllDatabaseChangesOnStartup(),
configureServices: services =>
{
services.AddMarten(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "ancillary_enrich_primary";
opts.Projections.Add<OrderProjection>(ProjectionLifecycle.Async);
})
.ApplyAllDatabaseChangesOnStartup();

services.AddMartenStore<IProductStore>(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "ancillary_enrich_products";
})
.ApplyAllDatabaseChangesOnStartup();
})
.StartAsync();
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = $"{SchemaName}_products";
})
.ApplyAllDatabaseChangesOnStartup();
});

_primaryStore = _host.Services.GetRequiredService<IDocumentStore>();
}

public async ValueTask DisposeAsync()
{
await _host.StopAsync();
_host.Dispose();
}

[Fact]
public async Task enrichment_from_ancillary_store_resolves_entity_and_maps_to_projection()
{
Expand Down
32 changes: 9 additions & 23 deletions src/EventSourcingTests/Bugs/Bug_4441_force_catch_up_with_outbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace EventSourcingTests.Bugs;
// IMessageBatch must catch up cleanly and the listener hooks must fire even
// when the projection raises no side effects.

public class Bug_4441_force_catch_up_with_outbox
public class Bug_4441_force_catch_up_with_outbox: HostedStoreContext
{
public class LetterCounts
{
Expand All @@ -55,17 +55,9 @@ public override LetterCounts Evolve(LetterCounts? snapshot, Guid id, IEvent e)
[Fact(Timeout = 30000)]
public async Task force_catch_up_returns_for_async_daemon_without_side_effects()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(s =>
{
s.AddMarten(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "bug4441_default";
m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async);
}).AddAsyncDaemon(DaemonMode.Solo);
})
.StartAsync();
var host = await StartHostAsync(
m => m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async),
DaemonMode.Solo);

var store = host.Services.GetRequiredService<IDocumentStore>();
await store.Advanced.Clean.CompletelyRemoveAllAsync();
Expand All @@ -86,18 +78,12 @@ public async Task force_catch_up_invokes_message_batch_lifecycle_with_custom_out
{
var outbox = new RecordingOutbox();

using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(s =>
var host = await StartHostAsync(m =>
{
s.AddMarten(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "bug4441_outbox";
m.Events.MessageOutbox = outbox;
m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async);
}).AddAsyncDaemon(DaemonMode.Solo);
})
.StartAsync();
m.Events.MessageOutbox = outbox;
m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async);
},
DaemonMode.Solo);

var store = host.Services.GetRequiredService<IDocumentStore>();
await store.Advanced.Clean.CompletelyRemoveAllAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace EventSourcingTests.Bugs;
// The mitigation degrades ForceAll under ExternallyManaged to a read-only wait-for-non-stale that never
// starts, stops, or drives an agent — so it can neither throw on the missing coordinator nor race the
// externally-owned agents into an out-of-order progression write. This test pins that Marten-side contract.
public class Bug_4904_force_catch_up_under_externally_managed
public class Bug_4904_force_catch_up_under_externally_managed: HostedStoreContext
{
public class LetterCounts
{
Expand All @@ -63,17 +63,9 @@ public override LetterCounts Evolve(LetterCounts? snapshot, Guid id, IEvent e)
[Fact(Timeout = 30000)]
public async Task force_catch_up_under_externally_managed_does_not_resolve_a_coordinator()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(s =>
{
s.AddMarten(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "bug4904_externally_managed";
m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async);
}).AddAsyncDaemon(DaemonMode.ExternallyManaged);
})
.StartAsync();
var host = await StartHostAsync(
m => m.Projections.Add<LetterCountsProjection>(ProjectionLifecycle.Async),
DaemonMode.ExternallyManaged);

var store = host.Services.GetRequiredService<IDocumentStore>();
await store.Advanced.Clean.CompletelyRemoveAllAsync();
Expand Down
3 changes: 3 additions & 0 deletions src/EventSourcingTests/EventSourcingTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
<Compile Include="..\Marten.Testing\Harness\DestructiveIntegrationContext.cs">
<Link>Harness\DestructiveIntegrationContext.cs</Link>
</Compile>
<Compile Include="..\Marten.Testing\Harness\HostedStoreContext.cs">
<Link>Harness\HostedStoreContext.cs</Link>
</Compile>
<Compile Include="..\Marten.Testing\Harness\IntegrationContext.cs">
<Link>Harness\IntegrationContext.cs</Link>
</Compile>
Expand Down
24 changes: 8 additions & 16 deletions src/EventSourcingTests/determining_the_event_store_identity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,19 @@

namespace EventSourcingTests;

public class determining_the_event_store_identity
public class determining_the_event_store_identity: HostedStoreContext
{
[Fact]
public async Task use_correct_identities()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
var host = await StartHostAsync(_ => { }, configureServices: services =>
{
services.AddMartenStore<IThingStore>(m =>
{
services.AddMarten(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "es_identity";
});

services.AddMartenStore<IThingStore>(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "things";
});

}).StartAsync();
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = $"{SchemaName}_things";
});
});

var stores = host.Services.GetServices<IEventStore>().ToArray();
stores.Single(x => x.GetType() == typeof(DocumentStore)).As<IEventStore>().Identity.ShouldBe(new EventStoreIdentity("main", "marten"));
Expand Down
52 changes: 15 additions & 37 deletions src/EventSourcingTests/generating_event_store_descriptors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,18 @@

namespace EventSourcingTests;

public class generating_event_store_descriptors
public class generating_event_store_descriptors: HostedStoreContext
{
[Fact]
public async Task find_default_capability_with_events_and_projections()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddMarten(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "capabilities";

opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async);
opts.Projections.Add<LapMultiStreamProjection>(ProjectionLifecycle.Inline);
opts.Projections.LiveStreamAggregation<QuestParty>();
opts.Projections.Add<MyAggregateProjection>(ProjectionLifecycle.Inline);
});
}).StartAsync();
var host = await StartHostAsync(opts =>
{
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async);
opts.Projections.Add<LapMultiStreamProjection>(ProjectionLifecycle.Inline);
opts.Projections.LiveStreamAggregation<QuestParty>();
opts.Projections.Add<MyAggregateProjection>(ProjectionLifecycle.Inline);
});

var capabilities = host.Services.GetServices<IEventStore>().ToArray();
capabilities.Length.ShouldBe(1);
Expand All @@ -54,19 +47,12 @@ public async Task find_default_capability_with_events_and_projections()
[Fact]
public async Task subscription_descriptors_carry_implementation_and_aggregate_types()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddMarten(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "descriptor_enrichment";

opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async);
opts.Projections.Add<LapMultiStreamProjection>(ProjectionLifecycle.Inline);
opts.Projections.Add<MyAggregateProjection>(ProjectionLifecycle.Inline);
});
}).StartAsync();
var host = await StartHostAsync(opts =>
{
opts.Projections.Snapshot<SimpleAggregate>(SnapshotLifecycle.Async);
opts.Projections.Add<LapMultiStreamProjection>(ProjectionLifecycle.Inline);
opts.Projections.Add<MyAggregateProjection>(ProjectionLifecycle.Inline);
});

var capability = host.Services.GetRequiredService<IEventStore>();
var usage = await capability.TryCreateUsage(CancellationToken.None);
Expand Down Expand Up @@ -96,15 +82,7 @@ public async Task subscription_descriptors_carry_implementation_and_aggregate_ty
[Fact]
public async Task max_event_sequence_matches_highest_persisted_seq_id()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddMarten(opts =>
{
opts.Connection(ConnectionSource.ConnectionString);
opts.DatabaseSchemaName = "max_seq_usage";
});
}).StartAsync();
var host = await StartHostAsync(_ => { });

var store = host.Services.GetRequiredService<IDocumentStore>();

Expand Down
19 changes: 6 additions & 13 deletions src/EventSourcingTests/propagate_logger_to_projections.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,16 @@

namespace EventSourcingTests;

public class propagate_logger_to_projections
public class propagate_logger_to_projections: HostedStoreContext
{
[Fact]
public async Task loggers_exist_on_projections()
{
using var host = await Host.CreateDefaultBuilder()
.ConfigureServices(services =>
{
services.AddMarten(m =>
{
m.Connection(ConnectionSource.ConnectionString);
m.DatabaseSchemaName = "system_part";

m.Projections.Add<SampleEventProjection>(ProjectionLifecycle.Inline);
m.Projections.Add<TestOrderingEventProjection>(ProjectionLifecycle.Inline);
});
}).StartAsync();
var host = await StartHostAsync(m =>
{
m.Projections.Add<SampleEventProjection>(ProjectionLifecycle.Inline);
m.Projections.Add<TestOrderingEventProjection>(ProjectionLifecycle.Inline);
});

var store = host.DocumentStore();
var projections = store.Options.As<StoreOptions>().Projections.All;
Expand Down
Loading
Loading