test(sql): route SchemaComplianceFixture.Dispose through the hardened TryDropDatabase — one drop-DDL shape per file (final-review carryover)
This commit is contained in:
@@ -73,23 +73,19 @@ public sealed class SchemaComplianceFixture : IDisposable
|
|||||||
return SqlTestDatabaseReaper.ReapOrphans(master, TestDatabasePrefix, DateTime.UtcNow - OrphanAge).Count;
|
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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
var masterConnection =
|
var masterConnection =
|
||||||
new SqlConnectionStringBuilder(ConnectionString) { InitialCatalog = "master" }.ConnectionString;
|
new SqlConnectionStringBuilder(ConnectionString) { InitialCatalog = "master" }.ConnectionString;
|
||||||
|
|
||||||
using var conn = new SqlConnection(masterConnection);
|
SqlTestDatabaseReaper.TryDropDatabase(masterConnection, DatabaseName);
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user