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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageVersion Include="Marten" Version="9.19.0" />
<PackageVersion Include="Marten.AspNetCore" Version="9.19.0" />
<PackageVersion Include="AndreGoepel.Marten.Configuration" Version="1.0.1" />
<PackageVersion Include="AndreGoepel.Marten.Testing" Version="1.0.0" />
</ItemGroup>

<ItemGroup Label="Scheduling">
Expand All @@ -44,7 +45,6 @@
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
<PackageVersion Include="NSubstitute" Version="6.0.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.13.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AndreGoepel.Marten.Testing" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Testcontainers.PostgreSql" />
<PackageReference Include="xunit.v3" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,64 +1,38 @@
using AndreGoepel.Marten.Configuration;
using JasperFx;
using Marten;
using Microsoft.Extensions.DependencyInjection;
using Testcontainers.PostgreSql;

namespace AndreGoepel.Marten.Identity.IntegrationTests.Infrastructure;

/// <summary>
/// Spins up a Postgres container and a Marten <see cref="IDocumentStore"/>
/// configured the way the production host configures it (projections,
/// schemas, identity wiring). Lives for the whole test collection so we
/// pay the container start-up cost once.
/// Configures the shared <see cref="AndreGoepel.Marten.Testing.MartenFixture"/> the way the
/// production host configures Marten (identity projections/schemas) via the package's documented
/// <c>ConfigureStore</c>/<c>OnStoreInitializedAsync</c> extension hooks, instead of re-implementing
/// the Postgres container lifecycle.
/// </summary>
public sealed class MartenFixture : IAsyncLifetime
public sealed class MartenFixture : AndreGoepel.Marten.Testing.MartenFixture
{
private PostgreSqlContainer _container = null!;

public IDocumentStore Store { get; private set; } = null!;

/// <summary>An <see cref="ISettingsStore"/> backed by <see cref="Store"/>, resolved
/// through the public DI registration rather than the package's internal type.</summary>
/// <summary>An <see cref="ISettingsStore"/> backed by <see cref="AndreGoepel.Marten.Testing.MartenFixture.Store"/>,
/// resolved through the public DI registration rather than the package's internal type.</summary>
public ISettingsStore SettingsStore { get; private set; } = null!;

// Pin the Postgres image by digest (not a mutable tag) so the test/CI
// environment can't be fed a different image behind the same tag (#37).
// Update via Dependabot/manual bump together with the digest.
private const string PostgresImage =
"postgres:16-alpine@sha256:e013e867e712fec275706a6c51c966f0bb0c93cfa8f51000f85a15f9865a28cb";
protected override void ConfigureStore(StoreOptions options) => options.InitializeIdentity();

public async ValueTask InitializeAsync()
protected override async ValueTask OnStoreInitializedAsync()
{
_container = new PostgreSqlBuilder(PostgresImage).Build();
await _container.StartAsync();

Store = DocumentStore.For(opts =>
{
opts.Connection(_container.GetConnectionString());
opts.InitializeIdentity();
opts.AutoCreateSchemaObjects = AutoCreate.All;
});

var services = new ServiceCollection();
services.AddSingleton(Store);
services.AddMartenConfiguration();
SettingsStore = services.BuildServiceProvider().GetRequiredService<ISettingsStore>();
}

public async ValueTask DisposeAsync()
{
await Store.DisposeAsync();
await _container.DisposeAsync();
}

/// <summary>
/// Wipes documents and event streams between tests without dropping
/// the schema (the schema rebuild is the slow part).
/// Wipes documents and event streams between tests without dropping the schema (the schema
/// rebuild is the slow part).
/// </summary>
public async Task ResetAsync(CancellationToken cancellationToken = default)
public override async Task ResetAsync(CancellationToken cancellationToken = default)
{
await Store.Advanced.Clean.DeleteAllDocumentsAsync(cancellationToken);
await base.ResetAsync(cancellationToken);
await Store.Advanced.Clean.DeleteAllEventDataAsync(cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
"version": 2,
"dependencies": {
"net10.0": {
"AndreGoepel.Marten.Testing": {
"type": "Direct",
"requested": "[1.0.0, )",
"resolved": "1.0.0",
"contentHash": "BjCrRNv7Y6phechbDHpfErJid3mJ9JSBQtu+4Wrpc6Al2hrGUQU3/wHe63MIDZGpi+tMFyMsI/PYMrsKQffQsA==",
"dependencies": {
"Marten": "9.19.0",
"Testcontainers.PostgreSql": "4.13.0",
"xunit.v3.extensibility.core": "3.2.2"
}
},
"coverlet.collector": {
"type": "Direct",
"requested": "[10.0.1, )",
Expand All @@ -27,15 +38,6 @@
"Castle.Core": "5.1.1"
}
},
"Testcontainers.PostgreSql": {
"type": "Direct",
"requested": "[4.13.0, )",
"resolved": "4.13.0",
"contentHash": "2ow4AE8drI9iA9Fr4ycAPusXPB1lJfQyyNONSMLE/XqLpm8VuNAh3pK38fOjkOWtTrnD03s4hAIdl4036Ik69A==",
"dependencies": {
"Testcontainers": "4.13.0"
}
},
"xunit.runner.visualstudio": {
"type": "Direct",
"requested": "[3.1.5, )",
Expand Down Expand Up @@ -318,6 +320,14 @@
"SharpZipLib": "1.4.2"
}
},
"Testcontainers.PostgreSql": {
"type": "Transitive",
"resolved": "4.13.0",
"contentHash": "2ow4AE8drI9iA9Fr4ycAPusXPB1lJfQyyNONSMLE/XqLpm8VuNAh3pK38fOjkOWtTrnD03s4hAIdl4036Ik69A==",
"dependencies": {
"Testcontainers": "4.13.0"
}
},
"Weasel.Core": {
"type": "Transitive",
"resolved": "9.17.0",
Expand Down