mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-30 17:24:37 -05:00
Fixing project names to fix VS bugs
For whatever reason, Visual Studio throws a fit if a referenced project has a name and the folder name (which is used to reference the project) is different than that name. To solve this issue, I've renamed all the projects and folders to match their project names as stated in the project.json.
This commit is contained in:
9
test/Microsoft.SqlTools.ServiceLayer.Test/App.config
Normal file
9
test/Microsoft.SqlTools.ServiceLayer.Test/App.config
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="xunit.methodDisplay" value="method"/>
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Connection Service tests
|
||||
/// </summary>
|
||||
public class ConnectionServiceTests
|
||||
{
|
||||
#region "Connection tests"
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ConnectToDatabaseTest()
|
||||
{
|
||||
// connect to a database instance
|
||||
var connectionResult =
|
||||
TestObjects.GetTestConnectionService()
|
||||
.Connect(TestObjects.GetTestConnectionDetails());
|
||||
|
||||
// verify that a valid connection id was returned
|
||||
Assert.True(connectionResult.ConnectionId > 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void OnConnectionCallbackHandlerTest()
|
||||
{
|
||||
bool callbackInvoked = false;
|
||||
|
||||
// setup connection service with callback
|
||||
var connectionService = TestObjects.GetTestConnectionService();
|
||||
connectionService.RegisterOnConnectionTask(
|
||||
(sqlConnection) => {
|
||||
callbackInvoked = true;
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
);
|
||||
|
||||
// connect to a database instance
|
||||
var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails());
|
||||
|
||||
// verify that a valid connection id was returned
|
||||
Assert.True(callbackInvoked);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// 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.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.WorkspaceServices.Contracts;
|
||||
using Microsoft.SqlTools.Test.Utility;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Language Service tests
|
||||
/// </summary>
|
||||
public class LanguageServiceTests
|
||||
{
|
||||
#region "Diagnostics tests"
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseSelectStatementWithoutErrors()
|
||||
{
|
||||
// sql statement with no errors
|
||||
const string sqlWithErrors = "SELECT * FROM sys.objects";
|
||||
|
||||
// get the test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse the sql statement
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there are no errors
|
||||
Assert.Equal(0, fileMarkers.Length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseSelectStatementWithError()
|
||||
{
|
||||
// sql statement with errors
|
||||
const string sqlWithErrors = "SELECT *** FROM sys.objects";
|
||||
|
||||
// get test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse sql statement
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there is one error
|
||||
Assert.Equal(1, fileMarkers.Length);
|
||||
|
||||
// verify the position of the error
|
||||
Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void ParseMultilineSqlWithErrors()
|
||||
{
|
||||
// multiline sql with errors
|
||||
const string sqlWithErrors =
|
||||
"SELECT *** FROM sys.objects;\n" +
|
||||
"GO\n" +
|
||||
"SELECT *** FROM sys.objects;\n";
|
||||
|
||||
// get test service
|
||||
LanguageService service = TestObjects.GetTestLanguageService();
|
||||
|
||||
// parse sql
|
||||
var scriptFile = new ScriptFile();
|
||||
scriptFile.SetFileContents(sqlWithErrors);
|
||||
ScriptFileMarker[] fileMarkers = service.GetSemanticMarkers(scriptFile);
|
||||
|
||||
// verify there are two errors
|
||||
Assert.Equal(2, fileMarkers.Length);
|
||||
|
||||
// check position of first error
|
||||
Assert.Equal(9, fileMarkers[0].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[0].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(1, fileMarkers[0].ScriptRegion.EndLineNumber);
|
||||
|
||||
// check position of second error
|
||||
Assert.Equal(9, fileMarkers[1].ScriptRegion.StartColumnNumber);
|
||||
Assert.Equal(3, fileMarkers[1].ScriptRegion.StartLineNumber);
|
||||
Assert.Equal(10, fileMarkers[1].ScriptRegion.EndColumnNumber);
|
||||
Assert.Equal(3, fileMarkers[1].ScriptRegion.EndLineNumber);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Autocomplete Tests"
|
||||
|
||||
/// <summary>
|
||||
/// Verify that the SQL parser correctly detects errors in text
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void AutocompleteTest()
|
||||
{
|
||||
var autocompleteService = TestObjects.GetAutoCompleteService();
|
||||
var connectionService = TestObjects.GetTestConnectionService();
|
||||
var connectionResult = connectionService.Connect(TestObjects.GetTestConnectionDetails());
|
||||
var sqlConnection = connectionService.ActiveConnections[connectionResult.ConnectionId];
|
||||
autocompleteService.UpdateAutoCompleteCache(sqlConnection);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
//
|
||||
// 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.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Serializers;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Message
|
||||
{
|
||||
public class MessageReaderWriterTests
|
||||
{
|
||||
const string TestEventString = "{\"type\":\"event\",\"event\":\"testEvent\",\"body\":null}";
|
||||
const string TestEventFormatString = "{{\"event\":\"testEvent\",\"body\":{{\"someString\":\"{0}\"}},\"seq\":0,\"type\":\"event\"}}";
|
||||
readonly int ExpectedMessageByteCount = Encoding.UTF8.GetByteCount(TestEventString);
|
||||
|
||||
private IMessageSerializer messageSerializer;
|
||||
|
||||
public MessageReaderWriterTests()
|
||||
{
|
||||
this.messageSerializer = new V8MessageSerializer();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WritesMessage()
|
||||
{
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
|
||||
MessageWriter messageWriter =
|
||||
new MessageWriter(
|
||||
outputStream,
|
||||
this.messageSerializer);
|
||||
|
||||
// Write the message and then roll back the stream to be read
|
||||
// TODO: This will need to be redone!
|
||||
await messageWriter.WriteMessage(HostingMessage.Event("testEvent", null));
|
||||
outputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
string expectedHeaderString =
|
||||
string.Format(
|
||||
Constants.ContentLengthFormatString,
|
||||
ExpectedMessageByteCount);
|
||||
|
||||
byte[] buffer = new byte[128];
|
||||
await outputStream.ReadAsync(buffer, 0, expectedHeaderString.Length);
|
||||
|
||||
Assert.Equal(
|
||||
expectedHeaderString,
|
||||
Encoding.ASCII.GetString(buffer, 0, expectedHeaderString.Length));
|
||||
|
||||
// Read the message
|
||||
await outputStream.ReadAsync(buffer, 0, ExpectedMessageByteCount);
|
||||
|
||||
Assert.Equal(
|
||||
TestEventString,
|
||||
Encoding.UTF8.GetString(buffer, 0, ExpectedMessageByteCount));
|
||||
|
||||
outputStream.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadsMessage()
|
||||
{
|
||||
MemoryStream inputStream = new MemoryStream();
|
||||
MessageReader messageReader =
|
||||
new MessageReader(
|
||||
inputStream,
|
||||
this.messageSerializer);
|
||||
|
||||
// Write a message to the stream
|
||||
byte[] messageBuffer = this.GetMessageBytes(TestEventString);
|
||||
inputStream.Write(
|
||||
this.GetMessageBytes(TestEventString),
|
||||
0,
|
||||
messageBuffer.Length);
|
||||
|
||||
inputStream.Flush();
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
HostingMessage messageResult = messageReader.ReadMessage().Result;
|
||||
Assert.Equal("testEvent", messageResult.Method);
|
||||
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadsManyBufferedMessages()
|
||||
{
|
||||
MemoryStream inputStream = new MemoryStream();
|
||||
MessageReader messageReader =
|
||||
new MessageReader(
|
||||
inputStream,
|
||||
this.messageSerializer);
|
||||
|
||||
// Get a message to use for writing to the stream
|
||||
byte[] messageBuffer = this.GetMessageBytes(TestEventString);
|
||||
|
||||
// How many messages of this size should we write to overflow the buffer?
|
||||
int overflowMessageCount =
|
||||
(int)Math.Ceiling(
|
||||
(MessageReader.DefaultBufferSize * 1.5) / messageBuffer.Length);
|
||||
|
||||
// Write the necessary number of messages to the stream
|
||||
for (int i = 0; i < overflowMessageCount; i++)
|
||||
{
|
||||
inputStream.Write(messageBuffer, 0, messageBuffer.Length);
|
||||
}
|
||||
|
||||
inputStream.Flush();
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Read the written messages from the stream
|
||||
for (int i = 0; i < overflowMessageCount; i++)
|
||||
{
|
||||
HostingMessage messageResult = messageReader.ReadMessage().Result;
|
||||
Assert.Equal("testEvent", messageResult.Method);
|
||||
}
|
||||
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReaderResizesBufferForLargeMessages()
|
||||
{
|
||||
MemoryStream inputStream = new MemoryStream();
|
||||
MessageReader messageReader =
|
||||
new MessageReader(
|
||||
inputStream,
|
||||
this.messageSerializer);
|
||||
|
||||
// Get a message with content so large that the buffer will need
|
||||
// to be resized to fit it all.
|
||||
byte[] messageBuffer =
|
||||
this.GetMessageBytes(
|
||||
string.Format(
|
||||
TestEventFormatString,
|
||||
new String('X', (int)(MessageReader.DefaultBufferSize * 3))));
|
||||
|
||||
inputStream.Write(messageBuffer, 0, messageBuffer.Length);
|
||||
inputStream.Flush();
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
HostingMessage messageResult = messageReader.ReadMessage().Result;
|
||||
Assert.Equal("testEvent", messageResult.Method);
|
||||
|
||||
inputStream.Dispose();
|
||||
}
|
||||
|
||||
private byte[] GetMessageBytes(string messageString, Encoding encoding = null)
|
||||
{
|
||||
if (encoding == null)
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
|
||||
byte[] messageBytes = Encoding.UTF8.GetBytes(messageString);
|
||||
byte[] headerBytes =
|
||||
Encoding.ASCII.GetBytes(
|
||||
string.Format(
|
||||
Constants.ContentLengthFormatString,
|
||||
messageBytes.Length));
|
||||
|
||||
// Copy the bytes into a single buffer
|
||||
byte[] finalBytes = new byte[headerBytes.Length + messageBytes.Length];
|
||||
Buffer.BlockCopy(headerBytes, 0, finalBytes, 0, headerBytes.Length);
|
||||
Buffer.BlockCopy(messageBytes, 0, finalBytes, headerBytes.Length, messageBytes.Length);
|
||||
|
||||
return finalBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Message
|
||||
{
|
||||
#region Request Types
|
||||
|
||||
internal class TestRequest
|
||||
{
|
||||
public Task ProcessMessage(MessageWriter messageWriter)
|
||||
{
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
internal class TestRequestArguments
|
||||
{
|
||||
public string SomeString { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Response Types
|
||||
|
||||
internal class TestResponse
|
||||
{
|
||||
}
|
||||
|
||||
internal class TestResponseBody
|
||||
{
|
||||
public string SomeString { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Types
|
||||
|
||||
internal class TestEvent
|
||||
{
|
||||
}
|
||||
|
||||
internal class TestEventBody
|
||||
{
|
||||
public string SomeString { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>2d771d16-9d85-4053-9f79-e2034737deef</ProjectGuid>
|
||||
<RootNamespace>Microsoft.SqlTools.ServiceLayer.Test</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'==''">.\obj</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SqlToolsEditorServices.Test.Transport.Stdio")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SqlToolsEditorServices.Test.Transport.Stdio")]
|
||||
[assembly: AssemblyCopyright("Copyright <20> 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("07137FCA-76D0-4CE7-9764-C21DB7A57093")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
||||
@@ -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.ServiceLayer.Hosting.Protocol.Serializers;
|
||||
using HostingMessage = Microsoft.SqlTools.ServiceLayer.Hosting.Protocol.Contracts.Message;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Test.ServiceHost
|
||||
{
|
||||
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(
|
||||
HostingMessage.Request(
|
||||
MessageId,
|
||||
MethodName,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkId: true,
|
||||
checkMethod: true,
|
||||
checkParams: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesEventMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
HostingMessage.Event(
|
||||
MethodName,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkMethod: true,
|
||||
checkParams: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesResponseMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
HostingMessage.Response(
|
||||
MessageId,
|
||||
null,
|
||||
MessageContent));
|
||||
|
||||
AssertMessageFields(
|
||||
messageObj,
|
||||
checkId: true,
|
||||
checkResult: true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializesResponseWithErrorMessages()
|
||||
{
|
||||
var messageObj =
|
||||
this.messageSerializer.SerializeMessage(
|
||||
HostingMessage.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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
108
test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs
Normal file
108
test/Microsoft.SqlTools.ServiceLayer.Test/Utility/TestObjects.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
//#define USE_LIVE_CONNECTION
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||
using Microsoft.SqlTools.ServiceLayer.LanguageServices;
|
||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.SqlTools.Test.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for the ServiceHost Connection Service tests
|
||||
/// </summary>
|
||||
public class TestObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a test connection service
|
||||
/// </summary>
|
||||
public static ConnectionService GetTestConnectionService()
|
||||
{
|
||||
#if !USE_LIVE_CONNECTION
|
||||
// use mock database connection
|
||||
return new ConnectionService(new TestSqlConnectionFactory());
|
||||
#else
|
||||
// connect to a real server instance
|
||||
return ConnectionService.Instance;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test connection details object
|
||||
/// </summary>
|
||||
public static ConnectionDetails GetTestConnectionDetails()
|
||||
{
|
||||
return new ConnectionDetails()
|
||||
{
|
||||
UserName = "sa",
|
||||
Password = "Yukon900",
|
||||
DatabaseName = "AdventureWorks2016CTP3_2",
|
||||
ServerName = "sqltools11"
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a test language service instance
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static LanguageService GetTestLanguageService()
|
||||
{
|
||||
return new LanguageService();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test autocomplete service instance
|
||||
/// </summary>
|
||||
public static AutoCompleteService GetAutoCompleteService()
|
||||
{
|
||||
return AutoCompleteService.Instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a test sql connection factory instance
|
||||
/// </summary>
|
||||
public static ISqlConnectionFactory GetTestSqlConnectionFactory()
|
||||
{
|
||||
#if !USE_LIVE_CONNECTION
|
||||
// use mock database connection
|
||||
return new TestSqlConnectionFactory();
|
||||
#else
|
||||
// connect to a real server instance
|
||||
return ConnectionService.Instance.ConnectionFactory;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test mock class for SqlConnection wrapper
|
||||
/// </summary>
|
||||
public class TestSqlConnection : ISqlConnection
|
||||
{
|
||||
public void OpenDatabaseConnection(string connectionString)
|
||||
{
|
||||
}
|
||||
|
||||
public IEnumerable<string> GetServerObjects()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test mock class for SqlConnection factory
|
||||
/// </summary>
|
||||
public class TestSqlConnectionFactory : ISqlConnectionFactory
|
||||
{
|
||||
public ISqlConnection CreateSqlConnection()
|
||||
{
|
||||
return new TestSqlConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
test/Microsoft.SqlTools.ServiceLayer.Test/packages.config
Normal file
11
test/Microsoft.SqlTools.ServiceLayer.Test/packages.config
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="net461" />
|
||||
<package id="xunit" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
|
||||
<package id="xunit.assert" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.core" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.extensibility.core" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.extensibility.execution" version="2.1.0" targetFramework="net45" />
|
||||
<package id="xunit.runner.visualstudio" version="2.1.0" targetFramework="net45" />
|
||||
</packages>
|
||||
33
test/Microsoft.SqlTools.ServiceLayer.Test/project.json
Normal file
33
test/Microsoft.SqlTools.ServiceLayer.Test/project.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "Microsoft.SqlTools.ServiceLayer.Test",
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable"
|
||||
},
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "9.0.1",
|
||||
"System.Runtime.Serialization.Primitives": "4.1.1",
|
||||
"System.Data.Common": "4.1.0",
|
||||
"System.Data.SqlClient": "4.1.0",
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-192208-24",
|
||||
"Microsoft.SqlTools.ServiceLayer": {
|
||||
"target": "project"
|
||||
}
|
||||
},
|
||||
"testRunner": "xunit",
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"portable-net451+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user