Path: redb-route/tests/redb.Route.Tests.Core/Integration/PostgresFreeFixture.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Core/Integration/PostgresFreeFixture.cs
----
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using redb.Core;
using redb.Core.Extensions;
using redb.Core.Models.Configuration;
using redb.Postgres.Extensions;
using redb.Route.RedbCore.Models;
namespace redb.Route.Tests.Core.Integration;
///
/// The Free counterpart of : the same Postgres database through AddRedb and the Free
/// provider, so the redb idempotent repository is shown to hold without Pro.
///
public sealed class PostgresFreeFixture : IAsyncLifetime
{
public IRedbService Redb { get; private set; } = null!;
public ServiceProvider ServiceProvider { get; private set; } = null!;
public async Task InitializeAsync()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
var connectionString = global::redb.Route.Tests.Shared.TestDatabases.Postgres(config.GetConnectionString("Postgres")!);
var services = new ServiceCollection();
services.AddLogging();
services.AddRedb(options => options
.UsePostgres(connectionString)
.Configure(c => c.PropsSaveStrategy = PropsSaveStrategy.DeleteInsert));
ServiceProvider = services.BuildServiceProvider();
Redb = ServiceProvider.GetRequiredService();
try
{
await Redb.InitializeAsync(ensureCreated: true);
}
catch
{
// Schema may already exist from the Pro fixture, a parallel TFM run or a previous session
await Redb.InitializeAsync();
}
await Redb.SyncSchemeAsync();
}
public async Task DisposeAsync()
{
if (ServiceProvider is IAsyncDisposable asyncDisposable)
await asyncDisposable.DisposeAsync();
else
ServiceProvider?.Dispose();
}
}
[CollectionDefinition("PostgresFree")]
public class PostgresFreeCollection : ICollectionFixture;