Example #1
0
        private string GetDefaultBackupFolderPath(CDataContainer dataContainer, SqlConnection sqlConn)
        {
            DisasterRecoveryService service          = new DisasterRecoveryService();
            BackupConfigInfo        backupConfigInfo = service.GetBackupConfigInfo(dataContainer, sqlConn, sqlConn.Database);

            return(backupConfigInfo.DefaultBackupFolder);
        }
Example #2
0
        private string GetDefaultBackupFullPath(DisasterRecoveryService service, string databaseName, CDataContainer dataContainer, SqlConnection sqlConn)
        {
            BackupConfigInfo backupConfigInfo = service.GetBackupConfigInfo(dataContainer, sqlConn, sqlConn.Database);

            return(Path.Combine(backupConfigInfo.DefaultBackupFolder, databaseName + ".bak"));
        }
Example #3
0
        //[Fact]
        public async void BackupFileBrowserTest()
        {
            string    databaseName = "testfilebrowser_" + new Random().Next(10000000, 99999999);
            SqlTestDb testDb       = SqlTestDb.CreateNew(TestServerType.OnPrem, false, databaseName);

            // Initialize backup service
            var liveConnection              = LiveConnectionHelper.InitLiveConnectionInfo(databaseName);
            DatabaseTaskHelper      helper  = AdminService.CreateDatabaseTaskHelper(liveConnection.ConnectionInfo, databaseExists: true);
            SqlConnection           sqlConn = ConnectionService.OpenSqlConnection(liveConnection.ConnectionInfo);
            DisasterRecoveryService disasterRecoveryService = new DisasterRecoveryService();
            BackupConfigInfo        backupConfigInfo        = disasterRecoveryService.GetBackupConfigInfo(helper.DataContainer, sqlConn, sqlConn.Database);

            // Create backup file
            string backupPath = Path.Combine(backupConfigInfo.DefaultBackupFolder, databaseName + ".bak");
            string query      = $"BACKUP DATABASE [{databaseName}] TO  DISK = N'{backupPath}' WITH NOFORMAT, NOINIT, NAME = N'{databaseName}-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10";
            await TestServiceProvider.Instance.RunQueryAsync(TestServerType.OnPrem, "master", query);

            FileBrowserService service = new FileBrowserService();

            string[] backupFilters = new string[2] {
                "*.bak", "*.trn"
            };
            var openParams = new FileBrowserOpenParams
            {
                OwnerUri    = liveConnection.ConnectionInfo.OwnerUri,
                ExpandPath  = backupConfigInfo.DefaultBackupFolder,
                FileFilters = backupFilters
            };

            var openBrowserEventFlowValidator = new EventFlowValidator <bool>()
                                                .AddEventValidation(FileBrowserOpenedNotification.Type, eventParams =>
            {
                Assert.True(eventParams.Succeeded);
                Assert.NotNull(eventParams.FileTree);
                Assert.NotNull(eventParams.FileTree.RootNode);
                Assert.NotNull(eventParams.FileTree.RootNode.Children);
                Assert.True(eventParams.FileTree.RootNode.Children.Count > 0);
                Assert.True(ContainsFileInTheFolder(eventParams.FileTree.SelectedNode, backupPath));
            })
                                                .Complete();

            await service.RunFileBrowserOpenTask(openParams, openBrowserEventFlowValidator.Object);

            // Verify complete notification event was fired and the result
            openBrowserEventFlowValidator.Validate();

            var expandParams = new FileBrowserExpandParams
            {
                OwnerUri   = liveConnection.ConnectionInfo.OwnerUri,
                ExpandPath = backupConfigInfo.DefaultBackupFolder
            };


            var expandEventFlowValidator = new EventFlowValidator <bool>()
                                           .AddEventValidation(FileBrowserExpandedNotification.Type, eventParams =>
            {
                Assert.True(eventParams.Succeeded);
                Assert.NotNull(eventParams.Children);
                Assert.True(eventParams.Children.Length > 0);
            })
                                           .Complete();

            // Expand the node in file browser
            await service.RunFileBrowserExpandTask(expandParams, expandEventFlowValidator.Object);

            // Verify result
            expandEventFlowValidator.Validate();

            var validateParams = new FileBrowserValidateParams
            {
                OwnerUri      = liveConnection.ConnectionInfo.OwnerUri,
                ServiceType   = FileValidationServiceConstants.Backup,
                SelectedFiles = new[] { backupPath }
            };

            var validateEventFlowValidator = new EventFlowValidator <bool>()
                                             .AddEventValidation(FileBrowserValidatedNotification.Type, eventParams => Assert.True(eventParams.Succeeded))
                                             .Complete();

            // Validate selected files in the browser
            await service.RunFileBrowserValidateTask(validateParams, validateEventFlowValidator.Object);

            // Verify complete notification event was fired and the result
            validateEventFlowValidator.Validate();

            // Remove the backup file
            if (File.Exists(backupPath))
            {
                File.Delete(backupPath);
            }
        }