mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-18 17:23:52 -05:00
Mege dev to master (#6)
* Merge master to dev (#4) * Misc. clean-ups related to removing unneeded PowerShell Language Service code. * Remove unneeded files and clean up remaining code. * Enable file change tracking with Workspace and EditorSession. * Merge ServiceHost xUnit test project into dev. (#5) * Setup standard src, test folder structure. Add unit test project. * Actually stage the deletes. Update .gitignore
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol;
|
||||
using Microsoft.SqlTools.EditorServices.Protocol.MessageProtocol.Serializers;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.EditorServices.Test.Protocol.LanguageServer
|
||||
{
|
||||
public class TestMessageContents
|
||||
{
|
||||
public const string SomeFieldValue = "Some value";
|
||||
public const int NumberValue = 42;
|
||||
|
||||
public string SomeField { get; set; }
|
||||
|
||||
public int Number { get; set; }
|
||||
|
||||
public TestMessageContents()
|
||||
{
|
||||
this.SomeField = SomeFieldValue;
|
||||
this.Number = NumberValue;
|
||||
}
|
||||
}
|
||||
|
||||
public class JsonRpcMessageSerializerTests
|
||||
{
|
||||
private IMessageSerializer messageSerializer;
|
||||
|
||||
private const string MessageId = "42";
|
||||
private const string MethodName = "testMethod";
|
||||
private static readonly JToken MessageContent = JToken.FromObject(new TestMessageContents());
|
||||
|
||||
public JsonRpcMessageSerializerTests()
|
||||
{
|
||||
this.messageSerializer = new JsonRpcMessageSerializer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesRequestMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
Message.Request(
|
||||
MessageId,
|
||||
MethodName,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkId: true,
|
||||
checkMethod: true,
|
||||
checkParams: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesEventMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
Message.Event(
|
||||
MethodName,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkMethod: true,
|
||||
checkParams: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesResponseMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
Message.Response(
|
||||
MessageId,
|
||||
null,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkId: true,
|
||||
checkResult: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesResponseWithErrorMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
Message.ResponseError(
|
||||
MessageId,
|
||||
null,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkId: true,
|
||||
checkError: true);
|
||||
}
|
||||
|
||||
private static void AssertMessageFields(
|
||||
JObject messageObj,
|
||||
bool checkId = false,
|
||||
bool checkMethod = false,
|
||||
bool checkParams = false,
|
||||
bool checkResult = false,
|
||||
bool checkError = false)
|
||||
{
|
||||
JToken token = null;
|
||||
|
||||
Assert.True(messageObj.TryGetValue("jsonrpc", out token));
|
||||
Assert.Equal("2.0", token.ToString());
|
||||
|
||||
if (checkId)
|
||||
{
|
||||
Assert.True(messageObj.TryGetValue("id", out token));
|
||||
Assert.Equal(MessageId, token.ToString());
|
||||
}
|
||||
|
||||
if (checkMethod)
|
||||
{
|
||||
Assert.True(messageObj.TryGetValue("method", out token));
|
||||
Assert.Equal(MethodName, token.ToString());
|
||||
}
|
||||
|
||||
if (checkError)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
else
|
||||
{
|
||||
string contentField = checkParams ? "params" : "result";
|
||||
Assert.True(messageObj.TryGetValue(contentField, out token));
|
||||
Assert.True(JToken.DeepEquals(token, MessageContent));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user