예제 #1
0
        public void RestoreDatabase_AllOptionsToggled_DoesNotThrow()
        {
            var newDatabaseName = "RestoredFromTest.Cake";

            try
            {
                //Arrange
                var path     = GetBackupFilePath();
                var settings = new RestoreSqlBackupSettings()
                {
                    NewDatabaseName        = newDatabaseName,
                    NewStorageFolder       = new DirectoryPath(Path.GetTempPath()),
                    WithReplace            = true,
                    SwitchToSingleUserMode = false,
                };

                // Act
                SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), settings);

                // Assert
                SqlHelpers.DbExists(ConnectionString, newDatabaseName);
            }
            finally
            {
                // Cleanup
                SqlHelpers.DropDatabase(ConnectionString, newDatabaseName);
            }
        }
예제 #2
0
        public void RestoreDatabase_NoSingleUserModeInformation_DoesNotThrow()
        {
            var originalDbName = "CakeRestoreTest";

            try
            {
                //Arrange
                var path     = GetBackupFilePath();
                var settings = new RestoreSqlBackupSettings()
                {
                    SwitchToSingleUserMode = false
                };

                // Act
                SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), settings);

                // Assert
                SqlHelpers.DbExists(ConnectionString, originalDbName);
            }
            finally
            {
                // Cleanup
                SqlHelpers.DropDatabase(ConnectionString, originalDbName);
            }
        }
예제 #3
0
        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
                SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), settings);

                // Assert
                SqlHelpers.DbExists(ConnectionString, newDatabaseName);
            }
            finally
            {
                // Cleanup
                SqlHelpers.DropDatabase(ConnectionString, newDatabaseName);
            }
        }
예제 #4
0
        public void Can_Read_DefaultDataPath()
        {
            using (var connection = SqlServerAliasesImpl.OpenSqlConnection(context, ConnectionString))
            {
                // Act
                var path = SqlBackupsImpl.GetDefaultDataPath(connection);

                // Assert
                path.Should().NotBeNullOrEmpty();
                Directory.Exists(path).Should().BeTrue();
            }
        }
예제 #5
0
        public void GetDatabaseName_Should_ReturnName()
        {
            using (var connection = SqlServerAliasesImpl.OpenSqlConnection(context, ConnectionString))
            {
                //Arrange
                var path = GetBackupFilePath();

                // Act
                var names = SqlBackupsImpl.GetDatabaseName(path, connection);

                // Assert
                names.Should().Be("CakeRestoreTest");
            }
        }
예제 #6
0
        public void Can_Read_LogicalNames()
        {
            using (var connection = SqlServerAliasesImpl.OpenSqlConnection(context, ConnectionString))
            {
                //Arrange
                var path = GetBackupFilePath();

                // Act
                var names = SqlBackupsImpl.GetLogicalNames(path, connection);

                // Assert
                names.Should().HaveCount(3);
            }
        }
예제 #7
0
        public void RestoreDatabase_DatabaseRename_DoesNotThrow()
        {
            var databaseName = "NewRandomDatabase";

            try
            {
                //Arrange
                var path = GetBackupFilePath();

                SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), new RestoreSqlBackupSettings()
                {
                    NewDatabaseName = databaseName
                });

                // Assert
                SqlHelpers.DbExists(ConnectionString, databaseName);
            }
            finally
            {
                // Cleanup
                SqlHelpers.DropDatabase(ConnectionString, databaseName);
            }
        }
예제 #8
0
        public void RestoreDatabase_WithReplace_DoesNotThrow()
        {
            var originalDbName = "CakeRestoreTest";

            try
            {
                //Arrange
                var path = GetBackupFilePath();

                // Act
                SqlBackupsImpl.RestoreSqlBackup(context, ConnectionString, new FilePath(path), new RestoreSqlBackupSettings()
                {
                    WithReplace = true
                });

                // Assert
                SqlHelpers.DbExists(ConnectionString, originalDbName);
            }
            finally
            {
                // Cleanup
                SqlHelpers.DropDatabase(ConnectionString, originalDbName);
            }
        }