public async Task SaveResultAsJsonFailure() { // Given: // ... A working query and workspace service WorkspaceService <SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary <string, byte[]> storage; QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null); await qes.HandleExecuteRequest(executeParams, executeRequest.Object); await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask; // If: I attempt to save a result set and get it to throw because of invalid column selection SaveResultsAsJsonRequestParams saveParams = new SaveResultsAsJsonRequestParams { BatchIndex = 0, FilePath = "qqq", OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, ColumnStartIndex = -1, ColumnEndIndex = 100, RowStartIndex = 0, RowEndIndex = 5 }; qes.JsonFileFactory = GetJsonStreamFactory(storage, saveParams); var efv = new EventFlowValidator <SaveResultRequestResult>() .AddStandardErrorValidation() .Complete(); await qes.HandleSaveResultsAsJsonRequest(saveParams, efv.Object); await qes.ActiveQueries[saveParams.OwnerUri] .Batches[saveParams.BatchIndex] .ResultSets[saveParams.ResultSetIndex] .SaveTasks[saveParams.FilePath]; // Then: // ... An error event should have been fired // ... No success event should have been fired efv.Validate(); }
public async Task SaveResultsAsXmlSuccess() { // Given: // ... A working query and workspace service WorkspaceService <SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery); ConcurrentDictionary <string, byte[]> storage; QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, ws, out storage); // ... The query execution service has executed a query with results var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri }; var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null); await qes.HandleExecuteRequest(executeParams, executeRequest.Object); await qes.WorkTask; await qes.ActiveQueries[Constants.OwnerUri].ExecutionTask; // If: I attempt to save a result set from a query SaveResultsAsXmlRequestParams saveParams = new SaveResultsAsXmlRequestParams { OwnerUri = Constants.OwnerUri, FilePath = "qqq", BatchIndex = 0, ResultSetIndex = 0, Formatted = true }; qes.XmlFileFactory = GetXmlStreamFactory(storage, saveParams); var efv = new EventFlowValidator <SaveResultRequestResult>() .AddStandardResultValidator() .Complete(); await qes.HandleSaveResultsAsXmlRequest(saveParams, efv.Object); await qes.ActiveQueries[saveParams.OwnerUri] .Batches[saveParams.BatchIndex] .ResultSets[saveParams.ResultSetIndex] .SaveTasks[saveParams.FilePath]; // Then: // ... I should have a successful result // ... There should not have been an error efv.Validate(); }
public async Task QueryDisposeMissingQuery() { // If: // ... I attempt to dispose a query that doesn't exist var workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >(); var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService.Object); var disposeParams = new QueryDisposeParams { OwnerUri = Constants.OwnerUri }; var disposeRequest = new EventFlowValidator <QueryDisposeResult>() .AddStandardErrorValidation() .Complete(); await queryService.HandleDisposeRequest(disposeParams, disposeRequest.Object); // Then: I should have received an error disposeRequest.Validate(); }
public static EventFlowValidator <TRequestContext> ValidateResultSetSummaries <TRequestContext>( this EventFlowValidator <TRequestContext> efv, List <ResultSetEventParams> resultSetEventParamList) { string GetResultSetKey(ResultSetSummary summary) => $"BatchId:{summary.BatchId}, ResultId:{summary.Id}"; // Separate the result set resultSetEventParamsList by batchid, resultsetid and by resultseteventtype. ConcurrentDictionary <string, List <ResultSetEventParams> > resultSetDictionary = new ConcurrentDictionary <string, List <ResultSetEventParams> >(); foreach (var resultSetEventParam in resultSetEventParamList) { resultSetDictionary .GetOrAdd(GetResultSetKey(resultSetEventParam.ResultSetSummary), (key) => new List <ResultSetEventParams>()) .Add(resultSetEventParam); } foreach (var(key, list) in resultSetDictionary) { ResultSetSummary completeSummary = null, lastResultSetSummary = null; int completeFlagCount = 0; for (int i = 0; i < list.Count; i++) { VerifyResultSummary(key, i, list, ref completeSummary, ref lastResultSetSummary, ref completeFlagCount); } // Verify that the completeEvent and lastResultSetSummary has same number of rows // if (lastResultSetSummary != null && completeSummary != null) { Assert.True(lastResultSetSummary.RowCount == completeSummary.RowCount, $"CompleteSummary and last Update Summary should have same number of rows, updateSummaryRowCount: {lastResultSetSummary.RowCount}, CompleteSummaryRowCount: {completeSummary.RowCount}"); } // Verify that we got exactly on complete Flag Count. // Assert.True(1 == completeFlagCount, $"Complete flag should be set in exactly once on Update Result Summary Event. Observed Count: {completeFlagCount}, \r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", list.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"); // Verify that the complete event was set on the last updateResultSet event. // Assert.True(list.Last().ResultSetSummary.Complete, $"Complete flag should be set on the last Update Result Summary event, , \r\nresultSetEventParamsList is:{string.Join("\r\n\t\t", list.ConvertAll((p) => p.GetType() + ":" + p.ResultSetSummary))}"); } return(efv); }
public async Task CancelNonExistantTest() { // If: // ... I request to cancel a query that doesn't exist var workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >(); var queryService = Common.GetPrimedExecutionService(null, false, false, false, workspaceService.Object); var cancelParams = new QueryCancelParams { OwnerUri = "Doesn't Exist" }; var cancelRequest = new EventFlowValidator <QueryCancelResult>() .AddResultValidation(r => { Assert.False(string.IsNullOrWhiteSpace(r.Messages)); }).Complete(); await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object); cancelRequest.Validate(); }
public async Task DisposeSuccess() { // Setup: Create an edit data service with a session var eds = new EditDataService(null, null, null); eds.ActiveSessions[Common.OwnerUri] = await GetDefaultSession(); // If: I ask to dispose of an existing session var efv = new EventFlowValidator <EditDisposeResult>() .AddResultValidation(Assert.NotNull) .Complete(); await eds.HandleDisposeRequest(new EditDisposeParams { OwnerUri = Common.OwnerUri }, efv.Object); // Then: // ... It should have completed successfully efv.Validate(); // ... And the session should have been removed from the active session list Assert.Empty(eds.ActiveSessions); }
public async Task SubsetServiceMissingQueryTest() { // If: // ... I ask for a set of results for a file that hasn't executed a query var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery); var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); var subsetParams = new SubsetParams { OwnerUri = Common.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0 }; var subsetRequest = new EventFlowValidator <SubsetResult>() .AddResultValidation(r => { // Then: Messages should not be null and the subset should be null Assert.NotNull(r.Message); Assert.Null(r.ResultSubset); }).Complete(); await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object); subsetRequest.Validate(); }
public async Task NullOrMissingSessionId(string sessionId) { // Setup: // ... Create a edit data service var eds = new EditDataService(null, null, null); // ... Create a session params that returns the provided session ID var mockParams = new EditCreateRowParams { OwnerUri = sessionId }; // If: I ask to perform an action that requires a session // Then: I should get an error from it var efv = new EventFlowValidator <EditDisposeResult>() .AddStandardErrorValidation() .Complete(); await eds.HandleSessionRequest(mockParams, efv.Object, session => null); efv.Validate(); }
public async Task SaveResultsCsvNonExistentQuery() { // Given: A working query and workspace service WorkspaceService <SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(null); QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, false, ws); // If: I attempt to save a result set from a query that doesn't exist SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams { OwnerUri = Constants.OwnerUri // Won't exist because nothing has executed }; var evf = new EventFlowValidator <SaveResultRequestResult>() .AddStandardErrorValidation() .Complete(); await qes.HandleSaveResultsAsCsvRequest(saveParams, evf.Object); // Then: // ... An error event should have been fired // ... No success event should have been fired evf.Validate(); }
public async Task QueryExecuteUnconnectedUriTest() { // Given: // If: // ... I request to execute a query using a file URI that isn't connected var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery); var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = "notConnected", QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator<ExecuteRequestResult>() .AddErrorValidation<string>(Assert.NotEmpty) .Complete(); await Common.AwaitExecution(queryService, queryParams, efv.Object); // Then: // ... All events should have been called as per their flow validator efv.Validate(); // ... There should be no active queries Assert.Empty(queryService.ActiveQueries); }
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(); }
// TODO https://github.com/Microsoft/vscode-mssql/issues/1003 reenable and make non-flaky // [Fact] public async Task SimpleExecuteErrorWithNoResultsTest() { var queryService = Common.GetPrimedExecutionService(null, true, false, false, null); var queryParams = new SimpleExecuteParams { OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery }; var efv = new EventFlowValidator <SimpleExecuteResult>() .AddSimpleExecuteErrorValidator(SR.QueryServiceResultSetHasNoResults) .Complete(); await queryService.HandleSimpleExecuteRequest(queryParams, efv.Object); await Task.WhenAll(queryService.ActiveSimpleExecuteRequests.Values); Query q = queryService.ActiveQueries.Values.First(); Assert.NotNull(q); q.ExecutionTask.Wait(); efv.Validate(); Assert.Equal(0, queryService.ActiveQueries.Count); }
public async Task CreateSucceeds() { // Setup: Create an edit data service with a session var eds = new EditDataService(null, null, null); eds.ActiveSessions[Constants.OwnerUri] = await GetDefaultSession(); // If: I ask to create a row from a non existant session var efv = new EventFlowValidator <EditCreateRowResult>() .AddResultValidation(ecrr => { Assert.True(ecrr.NewRowId > 0); }) .Complete(); await eds.HandleCreateRowRequest(new EditCreateRowParams { OwnerUri = Constants.OwnerUri }, efv.Object); // Then: // ... It should have been successful efv.Validate(); // ... There should be a create in the session EditSession s = eds.ActiveSessions[Constants.OwnerUri]; Assert.True(s.EditCache.Any(e => e.Value is RowCreate)); }
public async Task DeleteSuccess() { // Setup: Create an edit data service with a session var eds = new EditDataService(null, null, null); eds.ActiveSessions[Constants.OwnerUri] = await GetDefaultSession(); // If: I validly ask to delete a row var efv = new EventFlowValidator <EditDeleteRowResult>() .AddResultValidation(Assert.NotNull) .Complete(); await eds.HandleDeleteRowRequest(new EditDeleteRowParams { OwnerUri = Constants.OwnerUri, RowId = 0 }, efv.Object); // Then: // ... It should be successful efv.Validate(); // ... There should be a delete in the session EditSession s = eds.ActiveSessions[Constants.OwnerUri]; Assert.True(s.EditCache.Any(e => e.Value is RowDelete)); }
public async Task SimpleExecuteVerifyResultsTest() { var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, null); var queryParams = new SimpleExecuteParams { OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery }; var efv = new EventFlowValidator <SimpleExecuteResult>() .AddSimpleExecuteQueryResultValidator(Common.StandardTestDataSet) .Complete(); await queryService.HandleSimpleExecuteRequest(queryParams, efv.Object); Query q; queryService.ActiveQueries.TryGetValue(Constants.OwnerUri, out q); // wait on the task to finish q.ExecutionTask.Wait(); efv.Validate(); Assert.Equal(0, queryService.ActiveQueries.Count); }
public async Task OperationThrows() { // Setup: // ... Create an edit data service with a session var eds = new EditDataService(null, null, null); eds.ActiveSessions[Common.OwnerUri] = await GetDefaultSession(); // ... Create a session param that returns the common owner uri var mockParams = new EditCreateRowParams { OwnerUri = Common.OwnerUri }; // If: I ask to perform an action that requires a session // Then: I should get an error from it var efv = new EventFlowValidator <EditDisposeResult>() .AddStandardErrorValidation() .Complete(); await eds.HandleSessionRequest(mockParams, efv.Object, s => { throw new Exception(); }); efv.Validate(); }
public static EventFlowValidator <TRequestContext> ValidateResultSetSummaries <TRequestContext>( this EventFlowValidator <TRequestContext> efv, List <ResultSetEventParams> resultSetEventParamList) { string GetResultSetKey(ResultSetSummary summary) { return($"BatchId:{summary.BatchId}, ResultId:{summary.Id}"); } // Separate the result set resultSetEventParamsList by batchid, resultsetid and by resultseteventtype. ConcurrentDictionary <string, List <ResultSetEventParams> > resultSetDictionary = new ConcurrentDictionary <string, List <ResultSetEventParams> >(); foreach (var resultSetEventParam in resultSetEventParamList) { resultSetDictionary .GetOrAdd(GetResultSetKey(resultSetEventParam.ResultSetSummary), (key) => new List <ResultSetEventParams>()) .Add(resultSetEventParam); } foreach (var(key, list) in resultSetDictionary) { ResultSetSummary completeSummary = null, lastResultSetSummary = null; for (int i = 0; i < list.Count; i++) { VerifyResultSummary(key, i, list, ref completeSummary, ref lastResultSetSummary); } // Verify that the completeEvent and lastResultSetSummary has same number of rows // if (lastResultSetSummary != null && completeSummary != null) { Assert.True(lastResultSetSummary.RowCount == completeSummary.RowCount, "CompleteSummary and last Update Summary should have same number of rows"); } } return(efv); }
public async Task QueryExecuteMissingSelectionTest() { // Given: // ... A workspace with a standard query is configured var workspaceService = Common.GetPrimedWorkspaceService(string.Empty); // If: // ... I request to execute a query with a missing query string var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService); var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = null}; var efv = new EventFlowValidator<ExecuteRequestResult>() .AddErrorValidation<string>(Assert.NotEmpty) .Complete(); await queryService.HandleExecuteRequest(queryParams, efv.Object); // Then: // ... Am error should have been sent efv.Validate(); // ... There should not be an active query Assert.Empty(queryService.ActiveQueries); }
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(); }
public async Task QueryExecuteInvalidQueryTest() { // If: // ... I request to execute a query that is invalid var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery); var queryService = Common.GetPrimedExecutionService(null, true, true, workspaceService); var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument}; var efv = new EventFlowValidator<ExecuteRequestResult>() .AddStandardQueryResultValidator() .AddStandardBatchStartValidator() .AddStandardBatchCompleteValidator() .AddStandardQueryCompleteValidator(1) .Complete(); await Common.AwaitExecution(queryService, queryParams, efv.Object); // Then: // ... Am error should have been sent efv.Validate(); // ... There should not be an active query Assert.Equal(1, queryService.ActiveQueries.Count); }
public async Task RevertCellSucceeds() { // Setup: // ... Create an edit data service with a session that has a pending cell edit var eds = new EditDataService(null, null, null); var session = await GetDefaultSession(); eds.ActiveSessions[Constants.OwnerUri] = session; // ... Make sure that the edit has revert capabilities var mockEdit = new Mock <RowEditBase>(); mockEdit.Setup(edit => edit.RevertCell(It.IsAny <int>())) .Returns(new EditRevertCellResult()); session.EditCache[0] = mockEdit.Object; // If: I ask to revert a cell that has a pending edit var efv = new EventFlowValidator <EditRevertCellResult>() .AddResultValidation(Assert.NotNull) .Complete(); var param = new EditRevertCellParams { OwnerUri = Constants.OwnerUri, RowId = 0 }; await eds.HandleRevertCellRequest(param, efv.Object); // Then: // ... It should have succeeded efv.Validate(); // ... The edit cache should be empty again EditSession s = eds.ActiveSessions[Constants.OwnerUri]; Assert.Empty(s.EditCache); }
public async Task ExecutionPlanServiceValidTest() { // If: // ... I have a query that has results in the form of an execution plan var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery); var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, false, workspaceService); var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Constants.OwnerUri, ExecutionPlanOptions = new ExecutionPlanOptions { IncludeActualExecutionPlanXml = false, IncludeEstimatedExecutionPlanXml = true } }; var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null); await queryService.HandleExecuteRequest(executeParams, executeRequest.Object); await queryService.WorkTask; await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask; // ... And I then ask for a valid execution plan var executionPlanParams = new QueryExecutionPlanParams { OwnerUri = Constants.OwnerUri, BatchIndex = 0, ResultSetIndex = 0 }; var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>() .AddResultValidation(r => { // Then: Messages should be null and execution plan should not be null Assert.NotNull(r.ExecutionPlan); }).Complete(); await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object); executionPlanRequest.Validate(); }
public async Task RevertRowSucceeds() { // Setup: Create an edit data service with a session that has an pending edit var eds = new EditDataService(null, null, null); var session = await GetDefaultSession(); session.EditCache[0] = new Mock <RowEditBase>().Object; eds.ActiveSessions[Constants.OwnerUri] = session; // If: I ask to revert a row that has a pending edit var efv = new EventFlowValidator <EditRevertRowResult>() .AddResultValidation(Assert.NotNull) .Complete(); await eds.HandleRevertRowRequest(new EditRevertRowParams { OwnerUri = Constants.OwnerUri, RowId = 0 }, efv.Object); // Then: // ... It should have succeeded efv.Validate(); // ... The edit cache should be empty again EditSession s = eds.ActiveSessions[Constants.OwnerUri]; Assert.Empty(s.EditCache); }
public static EventFlowValidator <ExecuteRequestResult> AddStandardQueryResultValidator( this EventFlowValidator <ExecuteRequestResult> efv) { // We just need to makes sure we get a result back, there's no params to validate return(efv.AddResultValidation(Assert.NotNull)); }
public async Task InitializeSessionSuccess() { // Setup: // .. Create a mock query var mockQueryResults = QueryExecution.Common.StandardTestDataSet; var cols = mockQueryResults[0].Columns; // ... Create a metadata factory that will return some generic column information var etm = Common.GetStandardMetadata(cols.ToArray()); Mock <IEditMetadataFactory> emf = new Mock <IEditMetadataFactory>(); emf.Setup(f => f.GetObjectMetadata(It.IsAny <DbConnection>(), It.IsAny <string[]>(), It.IsAny <string>())) .Returns(etm); // ... Create a query execution service that will return a successful query var qes = QueryExecution.Common.GetPrimedExecutionService(mockQueryResults, true, false, false, null); // ... Create a connection service that doesn't throw when asked for a connection var cs = new Mock <ConnectionService>(); cs.Setup(s => s.GetOrOpenConnection(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>())) .Returns(Task.FromResult <DbConnection>(null)); // ... Create an edit data service that has mock providers var eds = new EditDataService(qes, cs.Object, emf.Object); // If: I request to initialize an edit data session var initParams = new EditInitializeParams { ObjectName = "testTable", OwnerUri = Constants.OwnerUri, ObjectType = "Table", Filters = new EditInitializeFiltering() }; var efv = new EventFlowValidator <EditInitializeResult>() .AddResultValidation(Assert.NotNull) .AddEventValidation(BatchStartEvent.Type, Assert.NotNull) .AddEventValidation(ResultSetCompleteEvent.Type, Assert.NotNull) .AddEventValidation(MessageEvent.Type, Assert.NotNull) .AddEventValidation(BatchCompleteEvent.Type, Assert.NotNull) .AddEventValidation(QueryCompleteEvent.Type, Assert.NotNull) .AddEventValidation(EditSessionReadyEvent.Type, esrp => { Assert.NotNull(esrp); Assert.Equal(Constants.OwnerUri, esrp.OwnerUri); Assert.True(esrp.Success); Assert.Null(esrp.Message); }) .Complete(); await eds.HandleInitializeRequest(initParams, efv.Object); await eds.ActiveSessions[Constants.OwnerUri].InitializeTask; // Then: // ... The event should have been received successfully efv.Validate(); // ... The session should have been created Assert.Equal(1, eds.ActiveSessions.Count); Assert.True(eds.ActiveSessions.Keys.Contains(Constants.OwnerUri)); }
//[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); } }