public void RestoreDatabase_MoveLocation_DoesNotThrow() { var newDatabaseName = "RestoredFromTest.Cake"; try { //Arrange var path = GetBackupFilePath(); var settings = new RestoreSqlBackupSettings() { NewDatabaseName = newDatabaseName, NewStorageFolder = new DirectoryPath(System.IO.Path.GetTempPath()) }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, newDatabaseName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, newDatabaseName); } }
public void RestoreMultipleDatabase_NoSingleUserModeInformation_DoesNotThrow() { var originalDbName = "CakeRestoreTest"; try { //Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); var settings = new RestoreSqlBackupSettings() { SwitchToSingleUserMode = false }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void RestoreDatabase_DatabaseRename_DoesNotThrow() { var databaseName = "NewRandomDatabase"; try { //Arrange var path = GetBackupFilePath(); RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings() { NewDatabaseName = databaseName }, new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, databaseName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, databaseName); } }
public void RestoreMultipleDatabase_WithReplace_DoesNotThrow() { var originalDbName = "CakeRestoreTest"; try { //Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings() { WithReplace = true }, pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void RestoreDatabase_AllOptionsToggled_DoesNotThrow() { var newDatabaseName = "RestoredFromTest.Cake"; try { //Arrange var path = GetBackupFilePath(); var settings = new RestoreSqlBackupSettings() { NewDatabaseName = newDatabaseName, NewStorageFolder = new DirectoryPath(System.IO.Path.GetTempPath()), WithReplace = true, SwitchToSingleUserMode = false, }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, newDatabaseName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, newDatabaseName); } }
public void RestoreMultipleDatabase_AllOptionsToggled_DoesNotThrow() { var newDatabaseName = "RestoredFromTest.Cake"; try { //Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); var settings = new RestoreSqlBackupSettings() { NewDatabaseName = newDatabaseName, NewStorageFolder = new DirectoryPath(System.IO.Path.GetTempPath()), WithReplace = true, SwitchToSingleUserMode = false, BackupSetFile = 1, DifferentialBackupSetFile = 1 }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, newDatabaseName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, newDatabaseName); } }
public void RestoreDatabase_NoSingleUserModeInformation_DoesNotThrow() { var originalDbName = "CakeRestoreTest"; try { //Arrange var path = GetBackupFilePath(); var settings = new RestoreSqlBackupSettings() { SwitchToSingleUserMode = false }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void RestoreMultipleDatabase_MoveLocation_DoesNotThrow() { var newDatabaseName = "RestoredFromTest.Cake"; try { //Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); var settings = new RestoreSqlBackupSettings() { NewDatabaseName = newDatabaseName, NewStorageFolder = new DirectoryPath(System.IO.Path.GetTempPath()) }; // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, settings, pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, newDatabaseName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, newDatabaseName); } }
public void RestoreDatabase_WithReplace_DoesNotThrow() { var originalDbName = "CakeRestoreTest"; try { //Arrange var path = GetBackupFilePath(); // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings() { WithReplace = true }, new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void Try_Restore_Bacpac() { try { SqlBacpacImpl.RestoreBacpac(context, ConnectionString, "NSaga", GetBacpacFilePath()); SqlHelpers.DbExists(ConnectionString, "Nsaga").Should().BeTrue(); } finally { SqlHelpers.DropDatabase(ConnectionString, "Nsaga"); } }
public void CreateDatabaseIfNotExists() { // Act var dbName = "CakeTest"; SqlServerAliases.CreateDatabaseIfNotExists(context, ConnectionString, dbName); // Assert SqlHelpers.DbExists(ConnectionString, dbName).Should().BeTrue(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }
public void DropDatabase_ActuallyDrops() { //Arrange var dbName = "WillBeDropped"; SqlHelpers.ExecuteSql(ConnectionString, $"Create database {dbName}"); // Act SqlServerAliases.DropDatabase(context, ConnectionString, dbName); // Assert SqlHelpers.DbExists(ConnectionString, dbName).Should().BeFalse(); }
public void CreateDatabase_Creates_Correctly() { // Act var dbName = "Unknown"; SqlServerAliases.CreateDatabase(context, ConnectionString, dbName); // Assert SqlHelpers.DbExists(ConnectionString, dbName).Should().BeTrue(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }
public void CreateDatabaseIfNotExists_DbExists_DoesNotThrow() { // Act var dbName = "ToBeRecreatedAgain"; SqlServerAliases.CreateDatabase(context, ConnectionString, dbName); SqlServerAliases.CreateDatabaseIfNotExists(context, ConnectionString, dbName); // Assert SqlHelpers.DbExists(ConnectionString, dbName).Should().BeTrue(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }
public void CreateDatabase_SqlNameInjection_DoesNotInject() { // Act SqlServerAliases.CreateDatabase(context, ConnectionString, "test] create database hack--"); // Assert SqlHelpers.DbExists(ConnectionString, "test").Should().BeFalse(); SqlHelpers.DbExists(ConnectionString, "hack").Should().BeFalse(); SqlHelpers.DbExists(ConnectionString, "test] create database hack--").Should().BeTrue(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('test')) is not null drop database [test]"); SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('hack')) is not null drop database [hack]"); SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('test] create database hack--')) is not null drop database [test]] create database hack--]"); }
public void CreateDatabaseIfNotExists_WithPrimaryFile() { // Act var dbName = "CakeTest"; var mdfFilePath = Path.Combine(Path.GetTempPath(), "MyCakeTest.mdf"); var createSettings = new CreateDatabaseSettings().WithPrimaryFile(mdfFilePath); SqlServerAliases.CreateDatabaseIfNotExists(context, ConnectionString, dbName, createSettings); // Assert SqlHelpers.DbExists(ConnectionString, dbName).Should().BeTrue(); File.Exists(mdfFilePath).Should().BeTrue(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, $"drop database {dbName}"); }
public void DropDatabase_LiteralInjection_DoesNotInject() { // Act try { SqlServerAliases.DropDatabase(context, ConnectionString, "some')) is null create database hack--"); } catch (Exception) { // do nothing } // Assert SqlHelpers.DbExists(ConnectionString, "hack").Should().BeFalse(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('hack')) is not null drop database [hack]"); }
public void DropDatabase_LiteralInjection_DoesNotInject() { // Act try { SqlServerAliases.DropDatabase(context, ConnectionString, "some')) is null create database hack--"); } #pragma warning disable CC0004 // Catch block cannot be empty catch { // do nothing } #pragma warning restore CC0004 // Catch block cannot be empty // Assert SqlHelpers.DbExists(ConnectionString, "hack").Should().BeFalse(); // Cleanup SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('hack')) is not null drop database [hack]"); }
public void RestoreDatabase_MinimalInformation_DoesNotThrow() { var originalDbName = "CakeRestoreTest"; try { //Arrange var path = GetBackupFilePath(); // Act SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), new RestoreSqlBackupSettings()); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void RestoreMultipleDatabase_MinimalInformation_DoesNotThrow() { const string originalDbName = "CakeRestoreTest"; try { // Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings(), pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName).Should().BeTrue(); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }
public void RestoreMultipleDatabase_DatabaseRename_DoesNotThrow() { const string databaseName = "NewRandomDatabase"; try { // Arrange var pathList = GetMultipleBackupFilePaths(); var differentialPathList = GetMultipleBackupFilePaths("differentialMultiFilesBackup*.bak"); RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings { NewDatabaseName = databaseName }, pathList, differentialBackupFiles: differentialPathList); // Assert SqlHelpers.DbExists(ConnectionString, databaseName).Should().BeTrue(); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, databaseName); } }
public void RestoreDatabase_MinimalInformation_DoesNotThrow() { const string originalDbName = "CakeRestoreTest"; try { // Arrange var path = GetBackupFilePath(); // Act RestoreSqlBackupImpl.RestoreSqlBackup(_context, ConnectionString, new RestoreSqlBackupSettings(), new List <FilePath> { new FilePath(path) }); // Assert SqlHelpers.DbExists(ConnectionString, originalDbName).Should().BeTrue(); } finally { // Cleanup SqlHelpers.DropDatabase(ConnectionString, originalDbName); } }