Exemple #1
0
        public async void ValidateSelectedFilesWithNullValidatorTest()
        {
            var liveConnection         = LiveConnectionHelper.InitLiveConnectionInfo();
            FileBrowserService service = new FileBrowserService();

            var validateParams = new FileBrowserValidateParams
            {
                // Do not pass any service so that the file validator will be null
                ServiceType   = "",
                OwnerUri      = liveConnection.ConnectionInfo.OwnerUri,
                SelectedFiles = new[] { "" }
            };

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

            // Validate files with null file validator
            await service.RunFileBrowserValidateTask(validateParams, efv.Object);

            efv.Validate();
        }
Exemple #2
0
        public async void InvalidFileValidationTest()
        {
            FileBrowserService service = new FileBrowserService();

            service.RegisterValidatePathsCallback("TestService", ValidatePaths);

            var validateParams = new FileBrowserValidateParams
            {
                // Do not pass any service so that the file validator will be null
                ServiceType   = "TestService",
                SelectedFiles = new[] { "" }
            };

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

            // Validate files with null file validator
            await service.RunFileBrowserValidateTask(validateParams, efv.Object);

            // Verify complete notification event was fired and the result
            efv.Validate();
        }
Exemple #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);
            }
        }