示例#1
0
        public async void CancelInProgressQueryTest()
        {
            // Set up file for returning the query
            var fileMock = new Mock <ScriptFile>();

            fileMock.Setup(file => file.GetLinesInRange(It.IsAny <BufferRange>()))
            .Returns(new[] { Common.StandardQuery });
            // Set up workspace mock
            var workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >();

            workspaceService.Setup(service => service.Workspace.GetFile(It.IsAny <string>()))
            .Returns(fileMock.Object);

            // If:
            // ... I request a query (doesn't matter what kind) and execute it
            var queryService = await Common.GetPrimedExecutionService(Common.CreateMockFactory(null, false), true, workspaceService.Object);

            var executeParams = new QueryExecuteParams {
                QuerySelection = Common.GetSubSectionDocument(), OwnerUri = Common.OwnerUri
            };
            var executeRequest =
                RequestContextMocks.SetupRequestContextMock <QueryExecuteResult, QueryExecuteCompleteParams>(null, QueryExecuteCompleteEvent.Type, null, null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;

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

            // ... And then I request to cancel the query
            var cancelParams = new QueryCancelParams {
                OwnerUri = Common.OwnerUri
            };
            QueryCancelResult result = null;
            var cancelRequest        = GetQueryCancelResultContextMock(qcr => result = qcr, null);

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

            // Then:
            // ... I should have seen a successful event (no messages)
            VerifyQueryCancelCallCount(cancelRequest, Times.Once(), Times.Never());
            Assert.Null(result.Messages);

            // ... The query should not have been disposed
            Assert.Equal(1, queryService.ActiveQueries.Count);
        }
示例#2
0
        public async Task CancelNonExistantTest()
        {
            var workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >();
            // If:
            // ... I request to cancel a query that doesn't exist
            var queryService = Common.GetPrimedExecutionService(null, false, false, workspaceService.Object);
            var cancelParams = new QueryCancelParams {
                OwnerUri = "Doesn't Exist"
            };
            QueryCancelResult result = null;
            var cancelRequest        = GetQueryCancelResultContextMock(qcr => result = qcr, null);
            await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);

            // Then:
            // ... I should have seen a result event with an error message
            VerifyQueryCancelCallCount(cancelRequest, Times.Once(), Times.Never());
            Assert.NotNull(result.Messages);
        }
示例#3
0
        public async void CancelExecutedQueryTest()
        {
            // Set up file for returning the query
            var fileMock = new Mock <ScriptFile>();

            fileMock.SetupGet(file => file.Contents).Returns(Common.StandardQuery);
            // Set up workspace mock
            var workspaceService = new Mock <WorkspaceService <SqlToolsSettings> >();

            workspaceService.Setup(service => service.Workspace.GetFile(It.IsAny <string>()))
            .Returns(fileMock.Object);
            // If:
            // ... I request a query (doesn't matter what kind) and wait for execution
            var queryService = await Common.GetPrimedExecutionService(Common.CreateMockFactory(null, false), true, workspaceService.Object);

            var executeParams = new QueryExecuteParams {
                QuerySelection = Common.WholeDocument, OwnerUri = Common.OwnerUri
            };
            var executeRequest =
                RequestContextMocks.SetupRequestContextMock <QueryExecuteResult, QueryExecuteCompleteParams>(null, QueryExecuteCompleteEvent.Type, null, null);
            await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);

            await queryService.ActiveQueries[Common.OwnerUri].ExecutionTask;

            // ... And then I request to cancel the query
            var cancelParams = new QueryCancelParams {
                OwnerUri = Common.OwnerUri
            };
            QueryCancelResult result = null;
            var cancelRequest        = GetQueryCancelResultContextMock(qcr => result = qcr, null);
            await queryService.HandleCancelRequest(cancelParams, cancelRequest.Object);

            // Then:
            // ... I should have seen a result event with an error message
            VerifyQueryCancelCallCount(cancelRequest, Times.Once(), Times.Never());
            Assert.NotNull(result.Messages);

            // ... The query should not have been disposed
            Assert.NotEmpty(queryService.ActiveQueries);
        }