mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
This change ensures that when calling `requestContext.SendError` you are only able to supply parameters that match the language service beta protocol expected Error object. In other words, you have to provide an error message and optionally and error code. # **BREAKING API CHANGES** This will break displaying errors in Microsoft/vscode-mssql. I will be making changes to properly handle the error object shortly. * Adding contract for returning Error objects as per LanguageService "protocol" * Fixes throughout codebase to send only error message in error cases Cleanup of CredentialServiceTest unit test class Adding standard error handling for event flow validator * Adding optional data field as per protocol spec https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md * Adding optional validation for error objects
65 lines
2.2 KiB
C#
65 lines
2.2 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.Hosting.Protocol;
|
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
|
using Moq;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.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<string, int, object> errorCallback)
|
|
{
|
|
// Setup the mock for SendError
|
|
var sendErrorFlow = mock.Setup(rc => rc.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()))
|
|
.Returns(Task.FromResult(0));
|
|
if (errorCallback != null)
|
|
{
|
|
sendErrorFlow.Callback<string, int, object>(errorCallback);
|
|
}
|
|
|
|
return mock;
|
|
}
|
|
}
|
|
}
|