private async Task TestSaveAsCsvSuccess(bool includeHeaders)
        {
            await this.RunFileSaveTest(async (filePath) =>
            {
                // Given: 
                // ... A simple data set that requires 1 message
                SerializeDataStartRequestParams saveParams = new SerializeDataStartRequestParams()
                {
                    FilePath = filePath,
                    Columns = DefaultColumns,
                    Rows = DefaultData,
                    IsLastBatch = true,
                    SaveFormat = "csv",
                    IncludeHeaders = includeHeaders
                };
                // When: I attempt to save this to a file
                var efv = new EventFlowValidator<SerializeDataResult>()
                    .AddStandardResultValidator()
                    .Complete();

                await SerializationService.RunSerializeStartRequest(saveParams, efv.Object);

                // Then:
                // ... There should not have been an error
                efv.Validate();
                // ... And the file should look as expected
                VerifyContents.VerifyCsvMatchesData(saveParams.Rows, saveParams.Columns, saveParams.IncludeHeaders, saveParams.FilePath);
            });
        }
        public async Task SimpleExecuteMultipleQueriesTest()
        {
            var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, null);
            var queryParams  = new SimpleExecuteParams {
                OwnerUri = Constants.OwnerUri, QueryString = Constants.StandardQuery
            };
            var efv1 = new EventFlowValidator <SimpleExecuteResult>()
                       .AddSimpleExecuteQueryResultValidator(Common.StandardTestDataSet)
                       .Complete();
            var efv2 = new EventFlowValidator <SimpleExecuteResult>()
                       .AddSimpleExecuteQueryResultValidator(Common.StandardTestDataSet)
                       .Complete();
            Task qT1 = queryService.HandleSimpleExecuteRequest(queryParams, efv1.Object);
            Task qT2 = queryService.HandleSimpleExecuteRequest(queryParams, efv2.Object);

            await Task.WhenAll(qT1, qT2);

            await Task.WhenAll(queryService.ActiveSimpleExecuteRequests.Values);

            var queries    = queryService.ActiveQueries.Values.ToArray();
            var queryTasks = queries.Select(query => query.ExecutionTask);

            await Task.WhenAll(queryTasks);

            efv1.Validate();
            efv2.Validate();

            Assert.Equal(0, queryService.ActiveQueries.Count);
        }
Пример #3
0
        public async void OpenFileBrowserTest()
        {
            var liveConnection         = LiveConnectionHelper.InitLiveConnectionInfo();
            FileBrowserService service = new FileBrowserService();

            var openParams = new FileBrowserOpenParams
            {
                OwnerUri    = liveConnection.ConnectionInfo.OwnerUri,
                ExpandPath  = "",
                FileFilters = new[] { "*" }
            };

            var efv = 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);
            })
                      .Complete();
            await service.RunFileBrowserOpenTask(openParams, efv.Object);

            efv.Validate();
        }
        public async Task QueryExecuteInProgressTest()
        {
            // If:
            // ... I request to execute a query
            var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
            var queryService = Common.GetPrimedExecutionService(null, true, false, workspaceService);
            var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};

            // Note, we don't care about the results of the first request
            var firstRequestContext = RequestContextMocks.Create<ExecuteRequestResult>(null);
            await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);

            // ... And then I request another query without waiting for the first to complete
            queryService.ActiveQueries[Common.OwnerUri].HasExecuted = false; // Simulate query hasn't finished
            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 only be one active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
        private async Task QueryExecuteAllBatchesNoOp()
        {
            // If:
            // ... I request to execute a valid query with all batches as no op
            var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.NoOpQuery));
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var queryParams      = new ExecuteDocumentSelectionParams {
                QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri
            };

            var efv = new EventFlowValidator <ExecuteRequestResult>()
                      .AddStandardQueryResultValidator()
                      .AddStandardBatchStartValidator()
                      .AddStandardMessageValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardMessageValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddEventValidation(QueryCompleteEvent.Type, p =>
            {
                // Validate OwnerURI matches
                Assert.Equal(Constants.OwnerUri, p.OwnerUri);
                Assert.NotNull(p.BatchSummaries);
                Assert.Equal(2, p.BatchSummaries.Length);
                Assert.All(p.BatchSummaries, bs => Assert.Equal(0, bs.ResultSetSummaries.Length));
            }).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 one active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
        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.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();
        }
Пример #7
0
        [InlineData(Common.OwnerUri, "table", null)]    // Null object type
        public async Task InitializeNullParams(string ownerUri, string objName, string objType)
        {
            // Setup: Create an edit data service without a session
            var eds = new EditDataService(null, null, null);

            // If:
            // ... I have init params with a null parameter
            var initParams = new EditInitializeParams
            {
                ObjectName = objName,
                OwnerUri   = ownerUri,
                ObjectType = objType
            };

            // ... And I initialize an edit session with that
            var efv = new EventFlowValidator <EditInitializeResult>()
                      .AddStandardErrorValidation()
                      .Complete();
            await eds.HandleInitializeRequest(initParams, efv.Object);

            // Then:
            // ... An error event should have been raised
            efv.Validate();

            // ... There should not be a session
            Assert.Empty(eds.ActiveSessions);
        }
Пример #8
0
        public async Task UpdateSuccess()
        {
            // Setup: Create an edit data service with a session
            var eds     = new EditDataService(null, null, null);
            var session = await GetDefaultSession();

            eds.ActiveSessions[Constants.OwnerUri] = session;
            var edit = new Mock <RowEditBase>();

            edit.Setup(e => e.SetCell(It.IsAny <int>(), It.IsAny <string>())).Returns(new EditUpdateCellResult
            {
                IsRowDirty = true,
                Cell       = new EditCell(new DbCellValue(), true)
            });
            session.EditCache[0] = edit.Object;

            // If: I validly ask to update a cell
            var efv = new EventFlowValidator <EditUpdateCellResult>()
                      .AddResultValidation(eucr =>
            {
                Assert.NotNull(eucr);
                Assert.NotNull(eucr.Cell);
                Assert.True(eucr.IsRowDirty);
            })
                      .Complete();
            await eds.HandleUpdateCellRequest(new EditUpdateCellParams { OwnerUri = Constants.OwnerUri, RowId = 0 }, efv.Object);

            // Then:
            // ... It should be successful
            efv.Validate();

            // ... Set cell should have been called once
            edit.Verify(e => e.SetCell(It.IsAny <int>(), It.IsAny <string>()), Times.Once);
        }
Пример #9
0
        public async Task GetRowsSuccess()
        {
            // Setup: Create an edit data service with a session
            // Setup: Create an edit data service with a session
            var eds     = new EditDataService(null, null, null);
            var session = await GetDefaultSession();

            eds.ActiveSessions[Constants.OwnerUri] = session;

            // If: I validly ask for rows
            var efv = new EventFlowValidator <EditSubsetResult>()
                      .AddResultValidation(esr =>
            {
                Assert.NotNull(esr);
                Assert.NotEmpty(esr.Subset);
                Assert.NotEqual(0, esr.RowCount);
            })
                      .Complete();
            await eds.HandleSubsetRequest(new EditSubsetParams
            {
                OwnerUri      = Constants.OwnerUri,
                RowCount      = 10,
                RowStartIndex = 0
            }, efv.Object);

            // Then:
            // ... It should be successful
            efv.Validate();
        }
        public async Task ExecutionPlanServiceUnexecutedQueryTest()
        {
            // If:
            // ... I have a query that hasn't finished executing (doesn't matter what)
            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.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasBeenRead = false;

            // ... And I then ask for a valid execution plan from it
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddStandardErrorValidation()
                                       .Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
        public async Task ExecutionPlanServiceOutOfRangeSubsetTest()
        {
            // If:
            // ... I have a query that doesn't have any result sets
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, 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.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            // ... And I then ask for an execution plan from a result set
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Constants.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddStandardErrorValidation()
                                       .Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
Пример #12
0
        public async Task DisposeExecutedQuery()
        {
            // If:
            // ... I request a query (doesn't matter what kind)
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams {
                QuerySelection = null, OwnerUri = Constants.OwnerUri
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.WorkTask;
            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            // ... And then I dispose of the query
            var disposeParams = new QueryDisposeParams {
                OwnerUri = Constants.OwnerUri
            };
            var disposeRequest = new EventFlowValidator <QueryDisposeResult>()
                                 .AddStandardQueryDisposeValidator()
                                 .Complete();
            await queryService.HandleDisposeRequest(disposeParams, disposeRequest.Object);

            // Then:
            // ... And the active queries should be empty
            disposeRequest.Validate();
            Assert.Empty(queryService.ActiveQueries);
        }
Пример #13
0
        public async Task CancelInProgressQueryTest()
        {
            // If:
            // ... I request a query (doesn't matter what kind) and execute it
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams {
                QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);

            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.WorkTask;
            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            queryService.ActiveQueries[Constants.OwnerUri].HasExecuted = false;    // Fake that it hasn't completed execution

            // ... And then I request to cancel the query
            var cancelParams = new QueryCancelParams {
                OwnerUri = Constants.OwnerUri
            };
            var cancelRequest = new EventFlowValidator <QueryCancelResult>()
                                .AddResultValidation(r =>
            {
                Assert.Null(r.Messages);
            }).Complete();
            await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);

            // Then:
            // ... The query should not have been disposed but should have been cancelled
            Assert.Equal(1, queryService.ActiveQueries.Count);
            Assert.Equal(true, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
            cancelRequest.Validate();
        }
        public async Task QueryExecuteCompletedTest()
        {
            // If:
            // ... I request to execute a query
            var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var queryParams      = new ExecuteDocumentSelectionParams {
                OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument
            };

            // Note, we don't care about the results of the first request
            var firstRequestContext = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await Common.AwaitExecution(queryService, queryParams, firstRequestContext.Object);

            // ... And then I request another query after waiting for the first to complete
            var efv = new EventFlowValidator <ExecuteRequestResult>()
                      .AddStandardQueryResultValidator()
                      .AddStandardBatchStartValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardQueryCompleteValidator(1)
                      .AddStandardQueryCompleteValidator(1)
                      .Complete();

            await Common.AwaitExecution(queryService, queryParams, efv.Object);

            // Then:
            // ... All events should have been called as per their flow validator
            efv.Validate();

            // ... There should only be one active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
        public async Task QueryExecuteInvalidQueryTest()
        {
            // If:
            // ... I request to execute a query that is invalid
            var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, true, false, workspaceService);
            var queryParams      = new ExecuteDocumentSelectionParams {
                OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument
            };

            var efv = new EventFlowValidator <ExecuteRequestResult>()
                      .AddStandardQueryResultValidator()
                      .AddStandardBatchStartValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardQueryCompleteValidator(1)
                      .AddStandardQueryCompleteValidator(1)
                      .Complete();
            await Common.AwaitExecution(queryService, queryParams, efv.Object);

            // Then:
            // ... An error should have been sent
            efv.Validate();

            // ... There should not be an active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
Пример #16
0
        public async Task SubsetServiceOutOfRangeSubsetTest()
        {
            // If:
            // ... I have a query that doesn't have any result sets
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams {
                QuerySelection = null, OwnerUri = Constants.OwnerUri
            };
            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 set of results from it
            var subsetParams = new SubsetParams {
                OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0
            };
            var subsetRequest = new EventFlowValidator <SubsetResult>()
                                .AddStandardErrorValidation()
                                .Complete();
            await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);

            subsetRequest.Validate();
        }
        public async Task QueryExecuteMultipleBatchSingleResultTest()
        {
            // If:
            // ... I request a to execute a valid query with multiple batches
            var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Constants.StandardQuery));
            var queryService     = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService);
            var queryParams      = new ExecuteDocumentSelectionParams {
                OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument
            };

            List <ResultSetEventParams> collectedResultSetEventParams = new List <ResultSetEventParams>();
            var efv = new EventFlowValidator <ExecuteRequestResult>()
                      .AddStandardQueryResultValidator()
                      .AddStandardBatchStartValidator()
                      .AddResultSetValidator(ResultSetAvailableEvent.Type, collectedResultSetEventParams)
                      .AddResultSetValidator(ResultSetUpdatedEvent.Type, collectedResultSetEventParams)
                      .AddResultSetValidator(ResultSetCompleteEvent.Type, collectedResultSetEventParams)
                      .AddStandardMessageValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardMessageValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardQueryCompleteValidator(2)
                      .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 one active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
Пример #18
0
        public async Task SubsetServiceUnexecutedQueryTest()
        {
            // If:
            // ... I have a query that hasn't finished executing (doesn't matter what)
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams {
                QuerySelection = null, OwnerUri = Constants.OwnerUri
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.WorkTask;
            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            queryService.ActiveQueries[Constants.OwnerUri].Batches[0].ResultSets[0].hasStartedRead = false;

            // ... And I then ask for a valid set of results from it
            var subsetParams = new SubsetParams {
                OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0
            };
            var subsetRequest = new EventFlowValidator <SubsetResult>()
                                .AddStandardErrorValidation()
                                .Complete();
            await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);

            subsetRequest.Validate();
        }
Пример #19
0
        public async Task SubsetServiceValidTest()
        {
            // If:
            // ... I have a query that has results (doesn't matter what)
            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
            };
            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 set of results from it
            var subsetParams = new SubsetParams {
                OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0
            };
            var subsetRequest = new EventFlowValidator <SubsetResult>()
                                .AddResultValidation(r =>
            {
                // Then: Subset should not be null
                Assert.NotNull(r.ResultSubset);
            }).Complete();
            await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);

            subsetRequest.Validate();
        }
Пример #20
0
        public async Task CancelExecutedQueryTest()
        {
            // If:
            // ... I request a query (doesn't matter what kind) and wait for execution
            var workspaceService = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, false, workspaceService);
            var executeParams    = new ExecuteDocumentSelectionParams {
                QuerySelection = Common.WholeDocument, OwnerUri = Constants.OwnerUri
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);

            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.WorkTask;
            await queryService.ActiveQueries[Constants.OwnerUri].ExecutionTask;

            // ... And then I request to cancel the query
            var cancelParams = new QueryCancelParams {
                OwnerUri = Constants.OwnerUri
            };
            var cancelRequest = new EventFlowValidator <QueryCancelResult>()
                                .AddResultValidation(r =>
            {
                Assert.False(string.IsNullOrWhiteSpace(r.Messages));
            }).Complete();

            await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);

            // Then:
            // ... The query should not have been disposed and cancel should not have excecuted
            Assert.NotEmpty(queryService.ActiveQueries);
            Assert.Equal(false, queryService.ActiveQueries[Constants.OwnerUri].HasCancelled);
            cancelRequest.Validate();
        }
Пример #21
0
        public async Task InitializeSessionExists()
        {
            // Setup: Create an edit data service with a session already defined
            var eds     = new EditDataService(null, null, null);
            var session = await GetDefaultSession();

            eds.ActiveSessions[Constants.OwnerUri] = session;

            // If: I request to init a session for an owner URI that already exists
            var initParams = new EditInitializeParams
            {
                ObjectName = "testTable",
                OwnerUri   = Constants.OwnerUri,
                ObjectType = "Table",
                Filters    = new EditInitializeFiltering()
            };
            var efv = new EventFlowValidator <EditInitializeResult>()
                      .AddStandardErrorValidation()
                      .Complete();
            await eds.HandleInitializeRequest(initParams, efv.Object);

            // Then:
            // ... An error event should have been sent
            efv.Validate();

            // ... The original session should still be there
            Assert.Equal(1, eds.ActiveSessions.Count);
            Assert.Equal(session, eds.ActiveSessions[Constants.OwnerUri]);
        }
        public async Task QueryExecuteSingleBatchSingleResultTest()
        {
            // If:
            // ... I request to execute a valid query with results
            var workspaceService = GetDefaultWorkspaceService(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, false, workspaceService);
            var queryParams      = new ExecuteDocumentSelectionParams {
                OwnerUri = Constants.OwnerUri, QuerySelection = Common.WholeDocument
            };

            var efv = new EventFlowValidator <ExecuteRequestResult>()
                      .AddStandardQueryResultValidator()
                      .AddStandardBatchStartValidator()
                      .AddStandardResultSetValidator()
                      .AddStandardMessageValidator()
                      .AddStandardBatchCompleteValidator()
                      .AddStandardQueryCompleteValidator(1)
                      .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 one active query
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
        private async Task SendAndVerifySerializeContinueRequest(SerializeDataContinueRequestParams request1)
        {
            // When: I attempt to save this to a file
            var efv = new EventFlowValidator<SerializeDataResult>()
                .AddStandardResultValidator()
                .Complete();

            await SerializationService.RunSerializeContinueRequest(request1, efv.Object);

            // Then:
            // ... There should not have been an error
            efv.Validate();
        }
Пример #24
0
        public async Task DisposeNullOrMissingSessionId(string sessionId)
        {
            // Setup: Create a edit data service
            var eds = new EditDataService(null, null, null);

            // 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.HandleDisposeRequest(new EditDisposeParams { OwnerUri = sessionId }, efv.Object);

            efv.Validate();
        }
        public async Task SaveResultAsCsvFailure()
        {
            // Given:
            // ... A working query and workspace service
            WorkspaceService <SqlToolsSettings>   ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
            ConcurrentDictionary <string, byte[]> storage;
            QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, 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 and get it to throw because of invalid column selection
            SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
            {
                BatchIndex       = 0,
                FilePath         = "qqq",
                OwnerUri         = Constants.OwnerUri,
                ResultSetIndex   = 0,
                ColumnStartIndex = -1,
                ColumnEndIndex   = 100,
                RowStartIndex    = 0,
                RowEndIndex      = 5
            };

            qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
            var efv = new EventFlowValidator <SaveResultRequestResult>()
                      .AddStandardErrorValidation()
                      .Complete();


            await qes.HandleSaveResultsAsCsvRequest(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();
        }
Пример #26
0
        public async Task ExecutionPlanServiceMissingQueryTest()
        {
            // If:
            // ... I ask for an execution plan for a file that hasn't executed a query
            var workspaceService    = Common.GetPrimedWorkspaceService(Common.StandardQuery);
            var queryService        = Common.GetPrimedExecutionService(null, true, false, workspaceService);
            var executionPlanParams = new QueryExecutionPlanParams {
                OwnerUri = Common.OwnerUri, ResultSetIndex = 0, BatchIndex = 0
            };
            var executionPlanRequest = new EventFlowValidator <QueryExecutionPlanResult>()
                                       .AddErrorValidation <string>(Assert.NotNull).Complete();
            await queryService.HandleExecutionPlanRequest(executionPlanParams, executionPlanRequest.Object);

            executionPlanRequest.Validate();
        }
Пример #27
0
        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(Constants.StandardQuery);
            var queryService     = Common.GetPrimedExecutionService(null, true, false, workspaceService);
            var subsetParams     = new SubsetParams {
                OwnerUri = Constants.OwnerUri, RowsCount = 1, ResultSetIndex = 0, RowsStartIndex = 0
            };
            var subsetRequest = new EventFlowValidator <SubsetResult>()
                                .AddStandardErrorValidation()
                                .Complete();
            await queryService.HandleResultSubsetRequest(subsetParams, subsetRequest.Object);

            subsetRequest.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();
        }
Пример #29
0
        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();
        }
Пример #30
0
        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();
        }