Path: redb/redb.Tests.Integration/Fixtures/MsSqlProFixture.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/MsSqlProFixture.cs ---- using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using redb.Core; using redb.Core.Data; using redb.Core.Models.Configuration; using redb.Core.Pro.Extensions; using redb.MSSql.Pro.Extensions; using redb.Tests.Integration.Models; namespace redb.Tests.Integration.Fixtures; public sealed class MsSqlProFixture : 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 cs = config.GetConnectionString("MSSql")!; var license = config["Redb:License"]; var services = new ServiceCollection(); services.AddLogging(b => b.AddConsole().SetMinimumLevel(LogLevel.Warning)); services.AddRedbPro(options => { options.UseMsSql(cs) .Configure(c => { c.PropsSaveStrategy = PropsSaveStrategy.ChangeTracking; c.SkipHashValidationOnCacheCheck = false; c.EnablePropsCache = false; c.EnablePvtPrefilter = ProTestOptions.PvtPrefilter; }); if (!string.IsNullOrWhiteSpace(license)) options.WithLicense(license); }); ServiceProvider = services.BuildServiceProvider(); Redb = ServiceProvider.GetRequiredService(); try { await Redb.InitializeAsync(ensureCreated: true); } catch { await Redb.InitializeAsync(); } await SyncSchemes(); await Cleanup(); } private async Task SyncSchemes() { await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); await Redb.SyncSchemeAsync(); } private async Task Cleanup() { var ctx = ServiceProvider.GetRequiredService(); await FixtureWipeGuard.EnsureLooksLikeATestDatabaseAsync(ctx, nameof(MsSqlProFixture)); try { await ctx.ExecuteAsync("DELETE FROM _tree"); } catch { } try { await ctx.ExecuteAsync("DELETE FROM _values"); } catch { } await ctx.ExecuteAsync("DELETE FROM _objects"); try { await ctx.ExecuteAsync("DBCC CHECKIDENT ('_objects', RESEED, 0)"); } catch { } try { await ctx.ExecuteAsync("DBCC CHECKIDENT ('_values', RESEED, 0)"); } catch { } } public async Task DisposeAsync() { if (ServiceProvider is IAsyncDisposable ad) await ad.DisposeAsync(); else ServiceProvider?.Dispose(); // Same as the Postgres fixtures: return the pooled sessions to the server immediately. Microsoft.Data.SqlClient.SqlConnection.ClearAllPools(); } }