public void DropAndCreateDatabase_Always_RemovesTable() { //Arrange var dbName = "ToBeRecreated"; var tableName = "WillNotExist"; SqlHelpers.ExecuteSql(ConnectionString, $"Create database {dbName}"); SqlHelpers.ExecuteSql(ConnectionString, $"create table [{dbName}].dbo.{tableName} (id int null)"); SqlHelpers.TableExists(ConnectionString, dbName, tableName).Should().BeTrue(); // Act SqlServerAliases.DropAndCreateDatabase(context, ConnectionString, dbName); // Assert SqlHelpers.TableExists(ConnectionString, dbName, tableName).Should().BeFalse(); SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }
public void ExecuteSqlFile_Executes_Successfuly() { //Arrange var connectionString = @"data source=(LocalDb)\v12.0;Database=ForFileExecution"; var dbName = "ForFileExecution"; var tableName1 = "WillExist1"; var tableName2 = "WillExist2"; SqlHelpers.ExecuteSql(ConnectionString, $"Create database {dbName}"); var sqlFilePath = GetSqlFilePath(); // Act SqlServerAliases.ExecuteSqlFile(context, connectionString, sqlFilePath); // Assert SqlHelpers.TableExists(ConnectionString, dbName, tableName1).Should().BeTrue(); SqlHelpers.TableExists(ConnectionString, dbName, tableName2).Should().BeTrue(); SqlServerAliases.DropDatabase(context, ConnectionString, dbName); }
public void Try_Publish_Dacpac() { var dbName = "DacpacTestDb"; try { // Arrange SqlHelpers.ExecuteSql(ConnectionString, $"create database {dbName}"); // Act SqlDacpacImpl.PublishDacpacFile(context, ConnectionString, dbName, GetDacpacFilePath()); // Assert SqlHelpers.TableExists(ConnectionString, dbName, "Table1").Should().BeTrue(); } finally { SqlHelpers.DropDatabase(ConnectionString, dbName); } }
public void DropAndCreateDatabase_WithCreateParams() { //Arrange var dbName = "ToBeRecreated"; var tableName = "WillNotExist"; SqlHelpers.ExecuteSql(ConnectionString, $"create database {dbName}"); SqlHelpers.ExecuteSql(ConnectionString, $"create table [{dbName}].dbo.{tableName} (id int null)"); SqlHelpers.TableExists(ConnectionString, dbName, tableName).Should().BeTrue(); var mdfFilePath = Path.Combine(Path.GetTempPath(), "MyCakeTest.mdf"); var logFilePath = Path.Combine(Path.GetTempPath(), "MyCakeTest.ldf"); var createSettings = new CreateDatabaseSettings().WithPrimaryFile(mdfFilePath).WithLogFile(logFilePath); // Act SqlServerAliases.DropAndCreateDatabase(context, ConnectionString, dbName, createSettings); // Assert File.Exists(mdfFilePath).Should().BeTrue(); File.Exists(logFilePath).Should().BeTrue(); }
public void ExecuteSqlCommand_CreatesTables() { //Arrange var dbName = "ForSqlExecution"; var tableName1 = "WillExist1"; var tableName2 = "WillExist2"; SqlHelpers.ExecuteSql(ConnectionString, $"Create database {dbName}"); var sql = $@" create table [{dbName}].dbo.{tableName1} (id int null); Go create table [{dbName}].dbo.{tableName2} (id int null); Go "; // Act SqlServerAliases.ExecuteSqlCommand(context, ConnectionString, sql); // Assert SqlHelpers.TableExists(ConnectionString, dbName, tableName1).Should().BeTrue(); SqlHelpers.TableExists(ConnectionString, dbName, tableName2).Should().BeTrue(); SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }