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 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_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);
            }
        }
Exemple #4
0
        public void Try_Create_Bacpac()
        {
            var dbName            = "BacpacTestDb";
            var resultingFilePath = "NsagaCreated.bacpac";

            try
            {
                // Arrange
                SqlHelpers.ExecuteSql(ConnectionString, $"Create database {dbName}");
                var sql = $@"use {dbName}
                GO
                create table [{dbName}].[dbo].[Table1] (id int null, name nvarchar(max) null);
                Go
                insert into [{dbName}].[dbo].[Table1] (id, name) values (42, 'Ultimate Question of Life');
                Go";
                context.ExecuteSqlCommand(ConnectionString, sql);

                // Act
                SqlBacpacImpl.CreateBacpacFile(context, ConnectionString, dbName, resultingFilePath);

                // Assert
                File.Exists(resultingFilePath).Should().BeTrue();
            }
            finally
            {
                SqlHelpers.DropDatabase(ConnectionString, dbName);
                File.Delete(resultingFilePath);
            }
        }
        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 Try_Extract_Dacpac()
        {
            var dbName            = "DacpacTestDb";
            var resultingFilePath = "NsagaCreated.dacpac";
            var settings          = new ExtractDacpacSettings("TestApp", "1.0.0.0")
            {
                OutputFile = resultingFilePath
            };

            try
            {
                // Arrange
                SqlHelpers.ExecuteSql(ConnectionString, $"create database {dbName}");
                var sql = $@"use {dbName}
                GO
                create table [{dbName}].[dbo].[Table1] (id int null, name nvarchar(max) null);
                Go";
                context.ExecuteSqlCommand(ConnectionString, sql);

                // Act
                SqlDacpacImpl.ExtractDacpacFile(context, ConnectionString, dbName, settings);

                // Assert
                File.Exists(resultingFilePath).Should().BeTrue();
            }
            finally
            {
                SqlHelpers.DropDatabase(ConnectionString, dbName);
                File.Delete(resultingFilePath);
            }
        }
        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 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 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);
            }
        }
Exemple #12
0
 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 Dispose()
 {
     SqlHelpers.DropDatabase(ConnectionString, "ForFileExecution");
     SqlHelpers.DropDatabase(ConnectionString, "WillBeDropped");
     SqlHelpers.DropDatabase(ConnectionString, "CakeTest");
     SqlHelpers.DropDatabase(ConnectionString, "ToBeRecreated");
     SqlHelpers.DropDatabase(ConnectionString, "ToBeRecreatedAgain");
     SqlHelpers.DropDatabase(ConnectionString, "ForSqlExecution");
     SqlHelpers.DropDatabase(ConnectionString, "Unknown");
     SqlHelpers.DropDatabase(ConnectionString, "test");
     SqlHelpers.DropDatabase(ConnectionString, "hack");
     SqlHelpers.DropDatabase(ConnectionString, "test]] create database hack--");
     SqlHelpers.ExecuteSql(ConnectionString, "if (select DB_ID('some'')) is null create database hack--')) is not null drop database [some')) is null create database hack--]");
 }
        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 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);
            }
        }
Exemple #16
0
        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);
            }
        }
Exemple #17
0
        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);
            }
        }
Exemple #18
0
        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);
            }
        }