public static void DropDatabase(this TestDatabase testDatabase) { var connectionString = new ConnectionStringBuilder() .WithServer(DatabaseExtensions.GetInstalledServerInstanceName()) .WithIntegratedSecurity() .Build(); var script = string.Format($@"USE master; ALTER DATABASE [{testDatabase.DatabaseName}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE [{testDatabase.DatabaseName}] ;"); using (var connection = new SqlConnection(connectionString)) { connection.ExecuteSql(script); } }
public static TestDatabase Create() { var connectionStringBuilder = new ConnectionStringBuilder() .WithServer(DatabaseExtensions.GetInstalledServerInstanceName()) .WithIntegratedSecurity(); var databaseName = string.Format($"SSISTesting-{Guid.NewGuid()}"); using (var connection = new SqlConnection(connectionStringBuilder.Build())) { connection.ExecuteSql(string.Format($"CREATE DATABASE [{databaseName}]")); } var testDatabaseConnectionString = connectionStringBuilder .WithDatabaseName(databaseName) .Build(); return(new TestDatabase(databaseName, testDatabaseConnectionString)); }