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
62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SqlTools.Hosting.Protocol;
|
|
using Moq;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Utility
|
|
{
|
|
public static class TestUtils
|
|
{
|
|
|
|
/// <summary>
|
|
/// Wait for a condition to be true for a limited amount of time.
|
|
/// </summary>
|
|
/// <param name="condition">Function that returns a boolean on a condition</param>
|
|
/// <param name="intervalMilliseconds">Number of milliseconds to wait between test intervals.</param>
|
|
/// <param name="intervalCount">Number of test intervals to perform before giving up.</param>
|
|
/// <returns>True if the condition was met before the test interval limit.</returns>
|
|
public static bool WaitFor(Func<bool> condition, int intervalMilliseconds = 10, int intervalCount = 200)
|
|
{
|
|
int count = 0;
|
|
while (count++ < intervalCount && !condition.Invoke())
|
|
{
|
|
Thread.Sleep(intervalMilliseconds);
|
|
}
|
|
|
|
return (count < intervalCount);
|
|
}
|
|
|
|
|
|
public static async Task RunAndVerify<T>(Func<RequestContext<T>, Task> test, Action<T> verify)
|
|
{
|
|
T result = default(T);
|
|
var contextMock = RequestContextMocks.Create<T>(r => result = r).AddErrorHandling(null);
|
|
await test(contextMock.Object);
|
|
VerifyResult(contextMock, verify, result);
|
|
}
|
|
|
|
public static void VerifyErrorSent<T>(Mock<RequestContext<T>> contextMock)
|
|
{
|
|
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Never);
|
|
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Once);
|
|
}
|
|
|
|
public static void VerifyResult<T, U>(Mock<RequestContext<T>> contextMock, U expected, U actual)
|
|
{
|
|
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Once);
|
|
Assert.Equal(expected, actual);
|
|
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Never);
|
|
}
|
|
|
|
public static void VerifyResult<T>(Mock<RequestContext<T>> contextMock, Action<T> verify, T actual)
|
|
{
|
|
contextMock.Verify(c => c.SendResult(It.IsAny<T>()), Times.Once);
|
|
contextMock.Verify(c => c.SendError(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<object>()), Times.Never);
|
|
verify(actual);
|
|
}
|
|
|
|
}
|
|
}
|