Path: redb/redb.Tests.Integration/Tests/Base/SchemaMissingTestsBase.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/Tests/Base/SchemaMissingTestsBase.cs ---- using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using redb.Core; using redb.Core.Exceptions; using redb.Core.Extensions; namespace redb.Tests.Integration.Tests.Base; /// /// InitializeAsync() without ensureCreated: true on a database that has no redb /// schema. Creation is opt-in by design (owner, 2026-09-12: the application role usually may not /// run DDL, and an unexpected empty database is more often a wrong connection string than a /// fresh installation) - but the failure used to be a raw driver error from the first start-up /// query, saying nothing about ensureCreated. Pinned: the situation is named by /// with the way out in the message, and the way out works. /// Each suite provides a throwaway empty database on its own server. /// public abstract class SchemaMissingTestsBase { /// Creates an empty database (no redb schema) and returns its connection string. protected abstract Task CreateEmptyDatabaseAsync(); /// Drops the database created by . protected abstract Task DropDatabaseAsync(string connectionString); protected abstract void UseProvider(RedbOptionsBuilder options, string connectionString); protected static string ConnString(string name) => new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile("appsettings.json") .Build() .GetConnectionString(name)!; private ServiceProvider Build(string connectionString) { var services = new ServiceCollection(); services.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning)); services.AddRedb(options => { UseProvider(options, connectionString); options.Configure(c => { c.EnablePropsCache = false; c.CacheDomain = $"schema-missing-{GetType().Name}"; }); }); return services.BuildServiceProvider(); } [Fact] public async Task InitializeWithoutEnsureCreated_OnAnEmptyDatabase_NamesTheSituation() { var cs = await CreateEmptyDatabaseAsync(); try { await using (var sp = Build(cs)) { var redb = sp.GetRequiredService(); var act = async () => await redb.InitializeAsync(); var thrown = await act.Should().ThrowAsync( "an empty database must be named as such, not surface a raw driver error from the first start-up query"); thrown.Which.Message.Should().Contain("ensureCreated: true", "the message must say how to get out of it"); } // The way out the message names works on the very same database. await using (var sp = Build(cs)) { var redb = sp.GetRequiredService(); await redb.InitializeAsync(ensureCreated: true); } } finally { await DropDatabaseAsync(cs); } } }