mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
The main feature of this pull request is a new callback that's added to the query class that is called when a batch has completed execution and retrieval of results. This callback will send an event to the extension with the batch summary information. After that, the extension can submit subset requests for the resultsets of the batch. Other smaller changes in this pull request: Refactor to assign a batch a id when its created instead of when returning the list of batch summaries Passing the SelectionData around instead of extracting the values for it Moving creation of BatchSummary into the Batch class Retrieval of results is now permitted even if the entire query has not completed, as long as the batch requested has completed. Also note, this does not break the protocol. It adds a new event that a queryRunner can listen to, but it doesn't require it to be listened to. * Refactor to remove SectionData class in favor of BufferRange * Adding callback for batch completion that will let the extension know that a batch has completed execution * Refactoring to make progressive results work as per async query execution * Allowing retrieval of batch results while query is in progress * reverting global.json, whoops * Adding a few missing comments, and fixing a couple code style bugs * Using SelectionData everywhere again * One more missing comment
77 lines
2.6 KiB
C#
77 lines
2.6 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts;
|
|
using Moq;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|
{
|
|
public static class RequestContextMocks
|
|
{
|
|
|
|
public static Mock<RequestContext<TResponse>> Create<TResponse>(Action<TResponse> resultCallback)
|
|
{
|
|
var requestContext = new Mock<RequestContext<TResponse>>();
|
|
|
|
// Setup the mock for SendResult
|
|
var sendResultFlow = requestContext
|
|
.Setup(rc => rc.SendResult(It.IsAny<TResponse>()))
|
|
.Returns(Task.FromResult(0));
|
|
if (resultCallback != null)
|
|
{
|
|
sendResultFlow.Callback(resultCallback);
|
|
}
|
|
return requestContext;
|
|
}
|
|
|
|
public static Mock<RequestContext<TResponse>> AddEventHandling<TResponse, TParams>(
|
|
this Mock<RequestContext<TResponse>> mock,
|
|
EventType<TParams> expectedEvent,
|
|
Action<EventType<TParams>, TParams> eventCallback)
|
|
{
|
|
var flow = mock.Setup(rc => rc.SendEvent(
|
|
It.Is<EventType<TParams>>(m => m == expectedEvent),
|
|
It.IsAny<TParams>()))
|
|
.Returns(Task.FromResult(0));
|
|
if (eventCallback != null)
|
|
{
|
|
flow.Callback(eventCallback);
|
|
}
|
|
|
|
return mock;
|
|
}
|
|
|
|
public static Mock<RequestContext<TResponse>> AddErrorHandling<TResponse>(
|
|
this Mock<RequestContext<TResponse>> mock,
|
|
Action<object> errorCallback)
|
|
{
|
|
// Setup the mock for SendError
|
|
var sendErrorFlow = mock.Setup(rc => rc.SendError(It.IsAny<object>()))
|
|
.Returns(Task.FromResult(0));
|
|
if (errorCallback != null)
|
|
{
|
|
sendErrorFlow.Callback(errorCallback);
|
|
}
|
|
|
|
return mock;
|
|
}
|
|
|
|
public static Mock<RequestContext<TResponse>> SetupRequestContextMock<TResponse, TParams>(
|
|
Action<TResponse> resultCallback,
|
|
EventType<TParams> expectedEvent,
|
|
Action<EventType<TParams>, TParams> eventCallback,
|
|
Action<object> errorCallback)
|
|
{
|
|
return Create(resultCallback)
|
|
.AddEventHandling(expectedEvent, eventCallback)
|
|
.AddErrorHandling(errorCallback);
|
|
}
|
|
|
|
}
|
|
}
|