Exemple #1
0
        public async Task SaveResultsCsvNonExistentQuery()

        {
            // Given: A working query and workspace service
            WorkspaceService <SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(null);
            QueryExecutionService qes = Common.GetPrimedExecutionService(null, false, false, ws);

            // If: I attempt to save a result set from a query that doesn't exist
            SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
            {
                OwnerUri = Common.OwnerUri  // Won't exist because nothing has executed
            };
            object error          = null;
            var    requestContext = RequestContextMocks.Create <SaveResultRequestResult>(null)
                                    .AddErrorHandling(o => error = o);
            await qes.HandleSaveResultsAsCsvRequest(saveParams, requestContext.Object);

            // Then:
            // ... An error event should have been fired
            // ... No success event should have been fired
            VerifyResponseCalls(requestContext, false, true);
            Assert.IsType <SaveResultRequestError>(error);
            Assert.NotNull(error);
            Assert.NotNull(((SaveResultRequestError)error).message);
        }
Exemple #2
0
        public async Task SaveResultAsCsvFailure()
        {
            // Given:
            // ... A working query and workspace service
            WorkspaceService <SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
            Dictionary <string, byte[]>         storage;
            QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);

            // ... The query execution service has executed a query with results
            var executeParams = new ExecuteDocumentSelectionParams {
                QuerySelection = null, OwnerUri = Common.OwnerUri
            };
            var executeRequest = RequestContextMocks.Create <ExecuteRequestResult>(null);
            await qes.HandleExecuteRequest(executeParams, executeRequest.Object);

            await qes.ActiveQueries[Common.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         = Common.OwnerUri,
                ResultSetIndex   = 0,
                ColumnStartIndex = -1,
                ColumnEndIndex   = 100,
                RowStartIndex    = 0,
                RowEndIndex      = 5
            };

            qes.CsvFileFactory = GetCsvStreamFactory(storage, saveParams);
            object error          = null;
            var    requestContext = RequestContextMocks.Create <SaveResultRequestResult>(null)
                                    .AddErrorHandling(e => error = e);
            await qes.HandleSaveResultsAsCsvRequest(saveParams, requestContext.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
            VerifyResponseCalls(requestContext, false, true);
            Assert.IsType <SaveResultRequestError>(error);
            Assert.NotNull(error);
            Assert.NotNull(((SaveResultRequestError)error).message);
        }
        public async Task SaveResultsAsCsvSuccess()
        {
            // 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 from a query
            SaveResultsAsCsvRequestParams saveParams = new SaveResultsAsCsvRequestParams
            {
                OwnerUri       = Constants.OwnerUri,
                FilePath       = "qqq",
                BatchIndex     = 0,
                ResultSetIndex = 0
            };

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

            await qes.HandleSaveResultsAsCsvRequest(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();
        }
Exemple #4
0
        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();
        }