Merge branch 'dev' into feature/queryExecutionV1

Also adding a fancy new mocked out reader for mocking db calls.
This commit is contained in:
Benjamin Russell
2016-08-01 14:27:57 -07:00
86 changed files with 475 additions and 181 deletions

View 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>

View File

@@ -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
}
}

View File

@@ -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).Wait();
}
#endregion
}
}

View File

@@ -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;
}
}
}

View File

@@ -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
}

View File

@@ -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>

View File

@@ -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")]

View File

@@ -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));
}
}
}
}

View File

@@ -0,0 +1,419 @@
//
// 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;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.ConnectionServices;
using Microsoft.SqlTools.ServiceLayer.ConnectionServices.Contracts;
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
}
}
public class TestSqlReader : IDataReader
{
#region Test Specific Implementations
internal string SqlCommandText { get; set; }
private const string tableNameTestCommand = "SELECT name FROM sys.tables";
private List<Dictionary<string, string>> tableNamesTest = new List<Dictionary<string, string>>
{
new Dictionary<string, string> { {"name", "table1"} },
new Dictionary<string, string> { {"name", "table2"} }
};
private IEnumerator<Dictionary<string, string>> tableEnumerator;
#endregion
public bool GetBoolean(int i)
{
throw new NotImplementedException();
}
public byte GetByte(int i)
{
throw new NotImplementedException();
}
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
public char GetChar(int i)
{
throw new NotImplementedException();
}
public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
public IDataReader GetData(int i)
{
throw new NotImplementedException();
}
public string GetDataTypeName(int i)
{
throw new NotImplementedException();
}
public DateTime GetDateTime(int i)
{
throw new NotImplementedException();
}
public decimal GetDecimal(int i)
{
throw new NotImplementedException();
}
public double GetDouble(int i)
{
throw new NotImplementedException();
}
public Type GetFieldType(int i)
{
throw new NotImplementedException();
}
public float GetFloat(int i)
{
throw new NotImplementedException();
}
public Guid GetGuid(int i)
{
throw new NotImplementedException();
}
public short GetInt16(int i)
{
throw new NotImplementedException();
}
public int GetInt32(int i)
{
throw new NotImplementedException();
}
public long GetInt64(int i)
{
throw new NotImplementedException();
}
public string GetName(int i)
{
throw new NotImplementedException();
}
public int GetOrdinal(string name)
{
throw new NotImplementedException();
}
public string GetString(int i)
{
throw new NotImplementedException();
}
public object GetValue(int i)
{
throw new NotImplementedException();
}
public int GetValues(object[] values)
{
throw new NotImplementedException();
}
public bool IsDBNull(int i)
{
throw new NotImplementedException();
}
public int FieldCount { get; }
object IDataRecord.this[string name]
{
get { return tableEnumerator.Current[name]; }
}
object IDataRecord.this[int i]
{
get { return tableEnumerator.Current[tableEnumerator.Current.Keys.ToArray()[i]]; }
}
public void Dispose()
{
throw new NotImplementedException();
}
public void Close()
{
throw new NotImplementedException();
}
public DataTable GetSchemaTable()
{
throw new NotImplementedException();
}
public bool NextResult()
{
throw new NotImplementedException();
}
public bool Read()
{
if (tableEnumerator == null)
{
switch (SqlCommandText)
{
case tableNameTestCommand:
tableEnumerator = ((IEnumerable<Dictionary<string, string>>)tableNamesTest).GetEnumerator();
break;
default:
throw new NotImplementedException();
}
}
return tableEnumerator.MoveNext();
}
public int Depth { get; }
public bool IsClosed { get; }
public int RecordsAffected { get; }
}
/// <summary>
/// Test mock class for IDbCommand
/// </summary>
public class TestSqlCommand : IDbCommand
{
public string CommandText { get; set; }
public int CommandTimeout { get; set; }
public CommandType CommandType { get; set; }
public IDbConnection Connection { get; set; }
public IDataParameterCollection Parameters
{
get
{
throw new NotImplementedException();
}
}
public IDbTransaction Transaction { get; set; }
public UpdateRowSource UpdatedRowSource { get; set; }
public void Cancel()
{
throw new NotImplementedException();
}
public IDbDataParameter CreateParameter()
{
throw new NotImplementedException();
}
public void Dispose()
{
}
public int ExecuteNonQuery()
{
throw new NotImplementedException();
}
public IDataReader ExecuteReader()
{
return new TestSqlReader
{
SqlCommandText = CommandText
};
}
public IDataReader ExecuteReader(CommandBehavior behavior)
{
throw new NotImplementedException();
}
public object ExecuteScalar()
{
throw new NotImplementedException();
}
public void Prepare()
{
throw new NotImplementedException();
}
}
/// <summary>
/// Test mock class for SqlConnection wrapper
/// </summary>
public class TestSqlConnection : ISqlConnection
{
public TestSqlConnection(string connectionString)
{
}
public void Dispose()
{
throw new System.NotImplementedException();
}
public IDbTransaction BeginTransaction()
{
throw new System.NotImplementedException();
}
public IDbTransaction BeginTransaction(IsolationLevel il)
{
throw new System.NotImplementedException();
}
public void Close()
{
throw new System.NotImplementedException();
}
public IDbCommand CreateCommand()
{
return new TestSqlCommand {Connection = this};
}
public void Open()
{
// No Op.
}
public string ConnectionString { get; set; }
public int ConnectionTimeout { get; }
public string Database { get; }
public ConnectionState State { get; }
public void ChangeDatabase(string databaseName)
{
throw new System.NotImplementedException();
}
public string DataSource { get; }
public string ServerVersion { get; }
public void ClearPool()
{
throw new System.NotImplementedException();
}
public async Task OpenAsync()
{
// No Op.
await Task.FromResult(0);
}
public Task OpenAsync(CancellationToken token)
{
throw new System.NotImplementedException();
}
}
/// <summary>
/// Test mock class for SqlConnection factory
/// </summary>
public class TestSqlConnectionFactory : ISqlConnectionFactory
{
public ISqlConnection CreateSqlConnection(string connectionString)
{
return new TestSqlConnection(connectionString);
}
}
}

View 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>

View 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"
]
}
}
}