Path: redb/redb.Tests.Integration/Fixtures/SchemaUpgradeCleanup.cs
Snapshot: redb, 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
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Fixtures/SchemaUpgradeCleanup.cs
----
namespace redb.Tests.Integration.Fixtures;
///
/// Removes what a schema-upgrade test class created on the test server (its databases, its login or role) when the
/// class is done, whether its tests passed or failed. The class registers the removal; the databases live for the whole
/// class, because every test of it starts from the deployed one.
///
public sealed class SchemaUpgradeCleanup : IAsyncLifetime
{
private Func? _remove;
///
/// A suffix of this run for the names of the databases and the login or role of the class: two runs on one server
/// (a host run and a direct one) must not drop each other's database in the middle of a test.
///
public string Suffix { get; } = Guid.NewGuid().ToString("N")[..8];
/// The removal of the first test instance is kept: every instance of a class names the same objects.
public void Register(Func remove) => _remove ??= remove;
public Task InitializeAsync() => Task.CompletedTask;
public Task DisposeAsync() => _remove?.Invoke() ?? Task.CompletedTask;
}