test(sql): route SchemaComplianceFixture.Dispose through the hardened TryDropDatabase — one drop-DDL shape per file (final-review carryover)

This commit is contained in:
Joseph Doherty
2026-08-17 06:15:28 -04:00
parent c15e5fc97b
commit f78f9cac28
@@ -73,23 +73,19 @@ public sealed class SchemaComplianceFixture : IDisposable
return SqlTestDatabaseReaper.ReapOrphans(master, TestDatabasePrefix, DateTime.UtcNow - OrphanAge).Count;
}
/// <summary>Disposes the fixture and drops the test database.</summary>
/// <summary>
/// Disposes the fixture and drops the test database — via the same parameterized
/// <see cref="SqlTestDatabaseReaper.TryDropDatabase"/> the reaper uses, so this file carries
/// exactly one drop-DDL shape. Best-effort like the AdminUI fixture's teardown: the name is
/// self-minted so a swallowed failure only leaks a database the startup reaper reclaims
/// within 24 h.
/// </summary>
public void Dispose()
{
var masterConnection =
new SqlConnectionStringBuilder(ConnectionString) { InitialCatalog = "master" }.ConnectionString;
using var conn = new SqlConnection(masterConnection);
conn.Open();
using var cmd = conn.CreateCommand();
cmd.CommandText = $@"
IF DB_ID(N'{DatabaseName}') IS NOT NULL
BEGIN
ALTER DATABASE [{DatabaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE [{DatabaseName}];
END";
cmd.ExecuteNonQuery();
SqlTestDatabaseReaper.TryDropDatabase(masterConnection, DatabaseName);
}
}