Perf Test fixing bugs and Update command (#155)

* Fixed some bugs caused by rafactoring

* Verifying a test db is created before running the tests
This commit is contained in:
Leila Lali
2016-11-30 12:56:48 -08:00
committed by GitHub
parent d1b791805a
commit 453ff9de15
19 changed files with 708 additions and 804 deletions

17
RefreshDllsForTestRun.cmd Normal file
View File

@@ -0,0 +1,17 @@
SET WORKINGDIR=%~dp0
SET _TargetLocation=%1
SET _BuildConfiguration=%2
IF [%_BuildConfiguration%] NEQ [] GOTO Start
SET _BuildConfiguration=Debug
:Start
SET _PerfTestSourceLocation="%WORKINGDIR%\test\Microsoft.SqlTools.ServiceLayer.PerfTests\bin\%_BuildConfiguration%\netcoreapp1.0\win7-x64\publish"
SET _ServiceSourceLocation="%WORKINGDIR%\src\Microsoft.SqlTools.ServiceLayer\bin\%_BuildConfiguration%\netcoreapp1.0\win7-x64\publish"
dotnet publish %WORKINGDIR%\test\Microsoft.SqlTools.ServiceLayer.PerfTests -c %_BuildConfiguration%
dotnet publish %WORKINGDIR%\src\Microsoft.SqlTools.ServiceLayer -c %_BuildConfiguration%
XCOPY /i /E /y %_PerfTestSourceLocation% "%_TargetLocation%\Tests"
XCOPY /i /E /y %_ServiceSourceLocation% "%_TargetLocation%\Microsoft.SqlTools.ServiceLayer"

View File

@@ -0,0 +1,39 @@
//
// 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.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Xunit.Sdk;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
/// <summary>
/// The attribute for each test to create the test db before the test starts
/// </summary>
public class CreateTestDbAttribute : BeforeAfterTestAttribute
{
public CreateTestDbAttribute(TestServerType serverType)
{
ServerType = serverType;
}
public CreateTestDbAttribute(int serverType)
{
ServerType = (TestServerType)serverType;
}
public TestServerType ServerType { get; set; }
public override void Before(MethodInfo methodUnderTest)
{
Task task = Common.CreateTestDatabase(ServerType);
task.Wait();
}
public override void After(MethodInfo methodUnderTest)
{
}
}
}

View File

@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests
Logger.Initialize("testdriver", LogLevel.Verbose); Logger.Initialize("testdriver", LogLevel.Verbose);
return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.Tests.").Result; return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.").Result;
} }
} }
} }

View File

@@ -4,18 +4,24 @@
// //
using System; using System;
using System.Globalization;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests; using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility; using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit; using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{ {
public class Common public class Common
{ {
public const string PerfTestDatabaseName = "SQLToolsCrossPlatPerfTestDb";
public const string MasterDatabaseName = "master";
internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func<Task<bool>> repeatedCode, internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func<Task<bool>> repeatedCode,
TimeSpan? delay = null, [CallerMemberName] string testName = "") TimeSpan? delay = null, [CallerMemberName] string testName = "")
{ {
@@ -38,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
} }
} }
internal static async Task<bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri) internal static async Task<bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri, string databaseName)
{ {
testHelper.WriteToFile(ownerUri, query); testHelper.WriteToFile(ownerUri, query);
@@ -56,7 +62,8 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
await testHelper.RequestOpenDocumentNotification(openParams); await testHelper.RequestOpenDocumentNotification(openParams);
Thread.Sleep(500); Thread.Sleep(500);
var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType); var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, databaseName);
bool connected = await testHelper.Connect(ownerUri, connectParams); bool connected = await testHelper.Connect(ownerUri, connectParams);
Assert.True(connected, "Connection is successful"); Assert.True(connected, "Connection is successful");
Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful"); Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");
@@ -64,13 +71,41 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
return connected; return connected;
} }
internal static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, [CallerMemberName] string testName = "") internal static async Task<T> CalculateRunTime<T>(Func<Task<T>> testToRun, bool printResult, [CallerMemberName] string testName = "")
{ {
TestTimer timer = new TestTimer(); TestTimer timer = new TestTimer() { PrintResult = printResult };
T result = await testToRun(); T result = await testToRun();
timer.EndAndPrint(testName); timer.EndAndPrint(testName);
return result; return result;
} }
/// <summary>
/// Create the test db if not already exists
/// </summary>
internal static async Task CreateTestDatabase(TestServerType serverType)
{
using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
string databaseName = Common.PerfTestDatabaseName;
string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
await RunQuery(testHelper, serverType, Common.MasterDatabaseName, createDatabaseQuery);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' is created", databaseName));
await RunQuery(testHelper, serverType, databaseName, Scripts.CreateDatabaseObjectsQuery);
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' SQL types are created", databaseName));
}
}
internal static async Task RunQuery(TestHelper testHelper, TestServerType serverType, string databaseName, string query)
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, databaseName);
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query, 50000), false);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
} }
} }

View File

@@ -11,18 +11,20 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit; using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{ {
public class ConnectionTests public class ConnectionTests
{ {
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task ConnectAzureTest() public async Task ConnectAzureTest()
{ {
TestServerType serverType = TestServerType.Azure;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
testHelper.WriteToFile(queryTempFile.FilePath, query); testHelper.WriteToFile(queryTempFile.FilePath, query);
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
@@ -41,20 +43,23 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
Thread.Sleep(500); Thread.Sleep(500);
var connected = await Common.CalculateRunTime(async () => var connected = await Common.CalculateRunTime(async () =>
{ {
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.Azure); var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, Common.PerfTestDatabaseName);
return await testHelper.Connect(queryTempFile.FilePath, connectParams); return await testHelper.Connect(queryTempFile.FilePath, connectParams);
}); }, true);
Assert.True(connected, "Connection was not successful"); Assert.True(connected, "Connection was not successful");
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task ConnectOnPremTest() public async Task ConnectOnPremTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
testHelper.WriteToFile(queryTempFile.FilePath, query); testHelper.WriteToFile(queryTempFile.FilePath, query);
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
@@ -73,22 +78,25 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
Thread.Sleep(500); Thread.Sleep(500);
var connected = await Common.CalculateRunTime(async () => var connected = await Common.CalculateRunTime(async () =>
{ {
var connectParams = await testHelper.GetDatabaseConnectionAsync(TestServerType.OnPrem); var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, Common.PerfTestDatabaseName);
return await testHelper.Connect(queryTempFile.FilePath, connectParams); return await testHelper.Connect(queryTempFile.FilePath, connectParams);
}); }, true);
Assert.True(connected, "Connection was not successful"); Assert.True(connected, "Connection was not successful");
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task DisconnectTest() public async Task DisconnectTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
Thread.Sleep(1000); Thread.Sleep(1000);
var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath)); var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath), true);
Assert.True(connected); Assert.True(connected);
} }
} }

View File

@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
// //
using System;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading; using System.Threading;
@@ -14,45 +15,53 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts; using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit; using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{ {
public class IntellisenseTests public class IntellisenseTests
{ {
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task HoverTestOnPrem() public async Task HoverTestOnPrem()
{ {
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15)); Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, Scripts.TestDbComplexSelectQueries.Length + 1), true);
Assert.NotNull(hover); Assert.NotNull(hover);
await testHelper.Disconnect(queryTempFile.FilePath); await testHelper.Disconnect(queryTempFile.FilePath);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task SuggestionsTest() public async Task SuggestionsTest()
{ {
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query, null); await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, false, Common.PerfTestDatabaseName, true);
await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query); await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, true, Common.PerfTestDatabaseName, false);
await testHelper.Disconnect(queryTempFile.FilePath); await testHelper.Disconnect(queryTempFile.FilePath);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task DiagnosticsTests() public async Task DiagnosticsTests()
{ {
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) TestServerType serverType = TestServerType.OnPrem;
await Common.CreateTestDatabase(serverType);
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{ {
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
Thread.Sleep(500); Thread.Sleep(500);
var contentChanges = new TextDocumentChangeEvent[1]; var contentChanges = new TextDocumentChangeEvent[1];
@@ -84,7 +93,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
} }
}; };
TestTimer timer = new TestTimer(); TestTimer timer = new TestTimer() { PrintResult = true };
await testHelper.RequestChangeTextDocumentNotification(changeParams); await testHelper.RequestChangeTextDocumentNotification(changeParams);
await Common.ExecuteWithTimeout(timer, 60000, async () => await Common.ExecuteWithTimeout(timer, 60000, async () =>
{ {
@@ -96,118 +105,172 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdAzureSimpleQuery() public async Task BindingCacheColdAzureSimpleQuery()
{ {
TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.SimpleQuery); await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, false);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheColdOnPremSimpleQuery() public async Task BindingCacheColdOnPremSimpleQuery()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery); await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbSimpleSelectQuery, false);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheWarmAzureSimpleQuery() public async Task BindingCacheWarmAzureSimpleQuery()
{ {
TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
const TestServerType serverType = TestServerType.Azure; await VerifyBindingLoadScenario(testHelper, serverType, query, true);
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
Thread.Sleep(10000);
await VerifyBindingLoadScenario(testHelper, serverType, query);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheWarmOnPremSimpleQuery() public async Task BindingCacheWarmOnPremSimpleQuery()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.TestDbSimpleSelectQuery;
const TestServerType serverType = TestServerType.OnPrem; await VerifyBindingLoadScenario(testHelper, serverType, query, true);
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
Thread.Sleep(10000);
await VerifyBindingLoadScenario(testHelper, serverType, query);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdAzureComplexQuery() public async Task BindingCacheColdAzureComplexQuery()
{ {
TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.ComplexQuery); await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbComplexSelectQueries,false);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdOnPremComplexQuery() public async Task BindingCacheColdOnPremComplexQuery()
{ {
TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.ComplexQuery); await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbComplexSelectQueries, false);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheWarmAzureComplexQuery() public async Task BindingCacheWarmAzureComplexQuery()
{ {
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
string query = Scripts.ComplexQuery; string query = Scripts.TestDbComplexSelectQueries;
const TestServerType serverType = TestServerType.Azure; const TestServerType serverType = TestServerType.Azure;
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath); await VerifyBindingLoadScenario(testHelper, serverType, query, true);
Thread.Sleep(10000);
await VerifyBindingLoadScenario(testHelper, serverType, query);
} }
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheWarmOnPremComplexQuery() public async Task BindingCacheWarmOnPremComplexQuery()
{ {
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
string query = Scripts.ComplexQuery; string query = Scripts.TestDbComplexSelectQueries;
const TestServerType serverType = TestServerType.OnPrem; const TestServerType serverType = TestServerType.OnPrem;
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath); await VerifyBindingLoadScenario(testHelper, serverType, query, true);
Thread.Sleep(10000);
await VerifyBindingLoadScenario(testHelper, serverType, query);
} }
} }
#region Private Helper Methods #region Private Helper Methods
private static async Task VerifyBindingLoadScenario(TestHelper testHelper, TestServerType serverType, string query, [CallerMemberName] string testName = "") private async Task VerifyBindingLoadScenario(
TestHelper testHelper,
TestServerType serverType,
string query,
bool preLoad,
[CallerMemberName] string testName = "")
{ {
using(SelfCleaningTempFile testTempFile = new SelfCleaningTempFile()) { string databaseName = Common.PerfTestDatabaseName;
if (preLoad)
{
await VerifyCompletationLoaded(testHelper, serverType, Scripts.TestDbSimpleSelectQuery,
databaseName, printResult: false, testName: testName);
Console.WriteLine("Intellisense cache loaded.");
}
await VerifyCompletationLoaded(testHelper, serverType, query, databaseName,
printResult: true, testName: testName);
}
private async Task VerifyCompletationLoaded(
TestHelper testHelper,
TestServerType serverType,
string query,
string databaseName,
bool printResult,
string testName)
{
using (SelfCleaningTempFile testTempFile = new SelfCleaningTempFile())
{
testHelper.WriteToFile(testTempFile.FilePath, query); testHelper.WriteToFile(testTempFile.FilePath, query);
await Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath, databaseName);
await ValidateCompletionResponse(testHelper, testTempFile.FilePath, query, testName); await ValidateCompletionResponse(testHelper, testTempFile.FilePath, printResult, databaseName,
waitForIntelliSense: true, testName: testName);
await testHelper.Disconnect(testTempFile.FilePath); await testHelper.Disconnect(testTempFile.FilePath);
} }
} }
private static async Task ValidateCompletionResponse(TestHelper testHelper, string ownerUri, string query, [CallerMemberName] string testName="") private static async Task ValidateCompletionResponse(
TestHelper testHelper,
string ownerUri,
bool printResult,
string databaseName,
bool waitForIntelliSense,
[CallerMemberName] string testName = "")
{ {
TestTimer timer = new TestTimer(); TestTimer timer = new TestTimer() { PrintResult = printResult };
await Common.ExecuteWithTimeout(timer, 60000, async () => bool isReady = !waitForIntelliSense;
await Common.ExecuteWithTimeout(timer, 150000, async () =>
{ {
CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, 15); if (isReady)
return completions != null && completions.Any(x => x.Label == "master"); {
}, testName:testName); string query = Scripts.SelectQuery;
} CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, query.Length + 1);
return completions != null && completions.Any(x => x.Label == databaseName);
}
else
{
var completeEvent = await testHelper.Driver.WaitForEvent(IntelliSenseReadyNotification.Type, 100000);
isReady = completeEvent.OwnerUri == ownerUri;
if (isReady)
{
Console.WriteLine("IntelliSense cache is loaded.");
}
return false;
}
}, testName: testName);
}
#endregion #endregion
} }

View File

@@ -12,20 +12,22 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility; using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Xunit; using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{ {
public class QueryExecutionTests public class QueryExecutionTests
{ {
[Fact] [Fact]
public async Task QueryResultSummaryOnPremTest() public async Task QueryResultSummaryOnPremTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.MasterBasicQuery;
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query)); var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query), true);
Assert.NotNull(queryResult); Assert.NotNull(queryResult);
Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0))); Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));
@@ -37,18 +39,20 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
[Fact] [Fact]
public async Task QueryResultFirstOnPremTest() public async Task QueryResultFirstOnPremTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.MasterBasicQuery;
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
var queryResult = await Common.CalculateRunTime(async () => var queryResult = await Common.CalculateRunTime(async () =>
{ {
await testHelper.RunQuery(queryTempFile.FilePath, query); await testHelper.RunQuery(queryTempFile.FilePath, query);
return await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100); return await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
}); }, true);
Assert.NotNull(queryResult); Assert.NotNull(queryResult);
Assert.NotNull(queryResult.ResultSubset); Assert.NotNull(queryResult.ResultSubset);
@@ -59,12 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
} }
[Fact] [Fact]
[CreateTestDb(TestServerType.OnPrem)]
public async Task CancelQueryOnPremTest() public async Task CancelQueryOnPremTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, Scripts.DelayQuery, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, Scripts.DelayQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);
var queryParams = new QueryExecuteParams var queryParams = new QueryExecuteParams
{ {
OwnerUri = queryTempFile.FilePath, OwnerUri = queryTempFile.FilePath,
@@ -74,9 +81,12 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
var result = await testHelper.Driver.SendRequest(QueryExecuteRequest.Type, queryParams); var result = await testHelper.Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
if (result != null && string.IsNullOrEmpty(result.Messages)) if (result != null && string.IsNullOrEmpty(result.Messages))
{ {
TestTimer timer = new TestTimer(); TestTimer timer = new TestTimer() { PrintResult = true };
await Common.ExecuteWithTimeout(timer, 100000, await Common.ExecuteWithTimeout(timer, 100000, async () =>
async () => await testHelper.CancelConnect(queryTempFile.FilePath), TimeSpan.FromMilliseconds(10)); {
var cancelQueryResult = await testHelper.CancelQuery(queryTempFile.FilePath);
return true;
}, TimeSpan.FromMilliseconds(10));
} }
else else
{ {

View File

@@ -9,23 +9,25 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility; using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Xunit; using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{ {
public class SaveResultsTests public class SaveResultsTests
{ {
[Fact] [Fact]
public async Task TestSaveResultsToCsvTest() public async Task TestSaveResultsToCsvTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.MasterBasicQuery;
// Execute a query // Execute a query
await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
await testHelper.RunQuery(queryTempFile.FilePath, query); await testHelper.RunQuery(queryTempFile.FilePath, query);
await Common.CalculateRunTime(() => testHelper.SaveAsCsv(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0)); await Common.CalculateRunTime(() => testHelper.SaveAsCsv(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0), true);
await testHelper.Disconnect(queryTempFile.FilePath); await testHelper.Disconnect(queryTempFile.FilePath);
} }
} }
@@ -33,17 +35,18 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
[Fact] [Fact]
public async Task TestSaveResultsToJsonTest() public async Task TestSaveResultsToJsonTest()
{ {
TestServerType serverType = TestServerType.OnPrem;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile()) using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper()) using (TestHelper testHelper = new TestHelper())
{ {
const string query = Scripts.SimpleQuery; const string query = Scripts.MasterBasicQuery;
const TestServerType serverType = TestServerType.OnPrem;
// Execute a query // Execute a query
await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath); await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
await testHelper.RunQuery(queryTempFile.FilePath, query); await testHelper.RunQuery(queryTempFile.FilePath, query);
await Common.CalculateRunTime(() => testHelper.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0)); await Common.CalculateRunTime(() => testHelper.SaveAsJson(queryTempFile.FilePath, outputTempFile.FilePath, 0, 0), true);
await testHelper.Disconnect(queryTempFile.FilePath); await testHelper.Disconnect(queryTempFile.FilePath);
} }
} }

View File

@@ -1,8 +1,12 @@
{ {
"name": "Microsoft.SqlTools.ServiceLayer.PerfTests",
"version": "1.0.0-*", "version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": { "dependencies": {
"xunit": "2.1.0", "xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24", "dotnet-test-xunit": "1.0.0-rc2-192208-24",
"Microsoft.SqlTools.ServiceLayer": { "Microsoft.SqlTools.ServiceLayer": {
"target": "project" "target": "project"
@@ -16,8 +20,7 @@
"netcoreapp1.0": { "netcoreapp1.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.App": { "Microsoft.NETCore.App": {
"type": "platform", "version": "1.0.0"
"version" : "1.0.0"
} }
}, },
"imports": [ "imports": [
@@ -25,5 +28,8 @@
"portable-net451+win8" "portable-net451+win8"
] ]
} }
},
"runtimes": {
"win7-x64": {}
} }
} }

View File

@@ -1,682 +0,0 @@
USE [AdventureWorks2016CTP3]
GO
SELECT [SystemInformationID]
,[Database Version]
,[VersionDate]
,[ModifiedDate]
FROM [dbo].[AWBuildVersion]
GO
GO
SELECT [DatabaseLogID]
,[PostTime]
,[DatabaseUser]
,[Event]
,[Schema]
,[Object]
,[TSQL]
,[XmlEvent]
FROM [dbo].[DatabaseLog]
GO
SELECT [OrderQty]
,[ProductID]
,[SpecialOfferID]
,[OrderID]
,[LocalID]
FROM [Demo].[DemoSalesOrderDetailSeed]
GO
SELECT [DueDate]
,[CustomerID]
,[SalesPersonID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[LocalID]
FROM [Demo].[DemoSalesOrderHeaderSeed]
GO
SELECT [DepartmentID]
,[Name]
,[GroupName]
,[ModifiedDate]
FROM [HumanResources].[Department]
GO
SELECT [BusinessEntityID]
,[NationalIDNumber]
,[LoginID]
,[OrganizationNode]
,[OrganizationLevel]
,[JobTitle]
,[BirthDate]
,[MaritalStatus]
,[Gender]
,[HireDate]
,[SalariedFlag]
,[VacationHours]
,[SickLeaveHours]
,[CurrentFlag]
,[rowguid]
,[ModifiedDate]
FROM [HumanResources].[Employee]
GO
SELECT [TrackingEventID]
,[EventName]
FROM [Sales].[TrackingEvent]
GO
SELECT [SalesTaxRateID]
,[StateProvinceID]
,[TaxType]
,[TaxRate]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesTaxRate]
GO
SELECT [SalesOrderID]
,[SalesOrderDetailID]
,[CarrierTrackingNumber]
,[OrderQty]
,[ProductID]
,[SpecialOfferID]
,[UnitPrice]
,[UnitPriceDiscount]
,[ModifiedDate]
FROM [Sales].[SalesOrderDetail_inmem]
GO
SELECT [SalesOrderID]
,[RevisionNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[SalesPersonID]
,[TerritoryID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesOrderHeader]
GO
SELECT [SalesOrderID]
,[RevisionNumber]
,[OrderDate]
,[DueDate]
,[ShipDate]
,[Status]
,[OnlineOrderFlag]
,[SalesOrderNumber]
,[PurchaseOrderNumber]
,[AccountNumber]
,[CustomerID]
,[SalesPersonID]
,[TerritoryID]
,[BillToAddressID]
,[ShipToAddressID]
,[ShipMethodID]
,[CreditCardID]
,[CreditCardApprovalCode]
,[CurrencyRateID]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[Comment]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[SalesOrder_json]
GO
SELECT [BusinessEntityID]
,[CreditCardID]
,[ModifiedDate]
FROM [Sales].[PersonCreditCard]
GO
SELECT [OrderTrackingID]
,[SalesOrderID]
,[CarrierTrackingNumber]
,[TrackingEventID]
,[EventDetails]
,[EventDateTime]
FROM [Sales].[OrderTracking]
GO
SELECT [CustomerID]
,[FirstName]
,[LastName]
,[SSN]
,[CreditCardNumber]
,[EmailAddress]
,[PhoneNumber]
,[TerritoryID]
FROM [Sales].[CustomerPII]
GO
SELECT [CustomerID]
,[PersonID]
,[StoreID]
,[TerritoryID]
,[AccountNumber]
,[rowguid]
,[ModifiedDate]
FROM [Sales].[Customer]
GO
SELECT [CurrencyRateID]
,[CurrencyRateDate]
,[FromCurrencyCode]
,[ToCurrencyCode]
,[AverageRate]
,[EndOfDayRate]
,[ModifiedDate]
FROM [Sales].[CurrencyRate]
GO
SELECT [CurrencyCode]
,[Name]
,[ModifiedDate]
FROM [Sales].[Currency]
GO
SELECT [CreditCardID]
,[CardType]
,[CardNumber]
,[ExpMonth]
,[ExpYear]
,[ModifiedDate]
FROM [Sales].[CreditCard]
GO
SELECT [CountryRegionCode]
,[CurrencyCode]
,[ModifiedDate]
FROM [Sales].[CountryRegionCurrency]
GO
SELECT [BusinessEntityID]
,[AccountNumber]
,[Name]
,[CreditRating]
,[PreferredVendorStatus]
,[ActiveFlag]
,[PurchasingWebServiceURL]
,[ModifiedDate]
FROM [Purchasing].[Vendor]
GO
SELECT [ShipMethodID]
,[Name]
,[ShipBase]
,[ShipRate]
,[rowguid]
,[ModifiedDate]
FROM [Purchasing].[ShipMethod]
GO
SELECT [PurchaseOrderID]
,[RevisionNumber]
,[Status]
,[EmployeeID]
,[VendorID]
,[ShipMethodID]
,[OrderDate]
,[ShipDate]
,[SubTotal]
,[TaxAmt]
,[Freight]
,[TotalDue]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderHeader]
GO
SELECT [PurchaseOrderID]
,[PurchaseOrderDetailID]
,[DueDate]
,[OrderQty]
,[ProductID]
,[UnitPrice]
,[LineTotal]
,[ReceivedQty]
,[RejectedQty]
,[StockedQty]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderDetail]
GO
SELECT [LocationID]
,[Name]
,[CostRate]
,[Availability]
,[ModifiedDate]
FROM [Production].[Location]
GO
SELECT [ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[rowguid]
,[ModifiedDate]
FROM [Production].[Product]
GO
SELECT [ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[ModifiedDate]
FROM [Production].[Product_inmem]
GO
SELECT [ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[ModifiedDate]
FROM [Production].[Product_ondisk]
GO
SELECT [ProductCategoryID]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductCategory]
GO
SELECT [ProductID]
,[StartDate]
,[EndDate]
,[StandardCost]
,[ModifiedDate]
FROM [Production].[ProductCostHistory]
GO
SELECT [ProductDescriptionID]
,[Description]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductDescription]
GO
SELECT [ProductID]
,[DocumentNode]
,[ModifiedDate]
FROM [Production].[ProductDocument]
GO
SELECT [ProductID]
,[LocationID]
,[Shelf]
,[Bin]
,[Quantity]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductInventory]
GO
SELECT [ProductID]
,[StartDate]
,[EndDate]
,[ListPrice]
,[ModifiedDate]
FROM [Production].[ProductListPriceHistory]
GO
SELECT [ProductModelID]
,[Name]
,[CatalogDescription]
,[Instructions]
,[rowguid]
,[ModifiedDate]
FROM [Production].[ProductModel]
GO
SELECT [ProductModelID]
,[IllustrationID]
,[ModifiedDate]
FROM [Production].[ProductModelIllustration]
GO
SELECT [ProductModelID]
,[IllustrationID]
,[ModifiedDate]
FROM [Production].[ProductModelIllustration]
GO
SELECT [ProductModelID]
,[ProductDescriptionID]
,[CultureID]
,[ModifiedDate]
FROM [Production].[ProductModelProductDescriptionCulture]
GO
SELECT [ProductPhotoID]
,[ThumbNailPhoto]
,[ThumbnailPhotoFileName]
,[LargePhoto]
,[LargePhotoFileName]
,[ModifiedDate]
FROM [Production].[ProductPhoto]
GO
SELECT [ProductID]
,[ProductPhotoID]
,[Primary]
,[ModifiedDate]
FROM [Production].[ProductProductPhoto]
GO
SELECT [ProductReviewID]
,[ProductID]
,[ReviewerName]
,[ReviewDate]
,[EmailAddress]
,[Rating]
,[Comments]
,[ModifiedDate]
FROM [Production].[ProductReview]
GO
SELECT [TransactionID]
,[ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionDate]
,[TransactionType]
,[Quantity]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[TransactionHistory]
GO
SELECT [TransactionID]
,[ProductID]
,[ReferenceOrderID]
,[ReferenceOrderLineID]
,[TransactionDate]
,[TransactionType]
,[Quantity]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[TransactionHistoryArchive]
GO
SELECT [UnitMeasureCode]
,[Name]
,[ModifiedDate]
FROM [Production].[UnitMeasure]
GO
SELECT [WorkOrderID]
,[ProductID]
,[OrderQty]
,[StockedQty]
,[ScrappedQty]
,[StartDate]
,[EndDate]
,[DueDate]
,[ScrapReasonID]
,[ModifiedDate]
FROM [Production].[WorkOrder]
GO
SELECT [WorkOrderID]
,[ProductID]
,[OperationSequence]
,[LocationID]
,[ScheduledStartDate]
,[ScheduledEndDate]
,[ActualStartDate]
,[ActualEndDate]
,[ActualResourceHrs]
,[PlannedCost]
,[ActualCost]
,[ModifiedDate]
FROM [Production].[WorkOrderRouting]
GO
SELECT [ProductID]
,[BusinessEntityID]
,[AverageLeadTime]
,[StandardPrice]
,[LastReceiptCost]
,[LastReceiptDate]
,[MinOrderQty]
,[MaxOrderQty]
,[OnOrderQty]
,[UnitMeasureCode]
,[ModifiedDate]
FROM [Purchasing].[ProductVendor]
GO
SELECT [PurchaseOrderID]
,[PurchaseOrderDetailID]
,[DueDate]
,[OrderQty]
,[ProductID]
,[UnitPrice]
,[LineTotal]
,[ReceivedQty]
,[RejectedQty]
,[StockedQty]
,[ModifiedDate]
FROM [Purchasing].[PurchaseOrderDetail]
GO
SELECT [AddressID]
,[AddressLine1]
,[AddressLine2]
,[City]
,[StateProvinceID]
,[PostalCode]
,[SpatialLocation]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Address]
GO
SELECT [AddressTypeID]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Person].[AddressType]
GO
SELECT [BusinessEntityID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntity]
GO
SELECT [BusinessEntityID]
,[AddressID]
,[AddressTypeID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntityAddress]
GO
SELECT [BusinessEntityID]
,[PersonID]
,[ContactTypeID]
,[rowguid]
,[ModifiedDate]
FROM [Person].[BusinessEntityContact]
GO
SELECT [ContactTypeID]
,[Name]
,[ModifiedDate]
FROM [Person].[ContactType]
GO
SELECT [CountryRegionCode]
,[Name]
,[ModifiedDate]
FROM [Person].[CountryRegion]
GO
SELECT [BusinessEntityID]
,[EmailAddressID]
,[EmailAddress]
,[rowguid]
,[ModifiedDate]
FROM [Person].[EmailAddress]
GO
SELECT [BusinessEntityID]
,[PasswordHash]
,[PasswordSalt]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Password]
GO
SELECT [BusinessEntityID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
,[Suffix]
,[EmailPromotion]
,[AdditionalContactInfo]
,[Demographics]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Person]
GO
SELECT [PersonID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
,[Suffix]
,[EmailPromotion]
,[AdditionalContactInfo]
,[Demographics]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Person_json]
GO
SELECT [BusinessEntityID]
,[NationalIDNumber]
,[LoginID]
,[OrganizationNode]
,[OrganizationLevel]
,[JobTitle]
,[BirthDate]
,[MaritalStatus]
,[Gender]
,[HireDate]
,[VacationHours]
,[SickLeaveHours]
,[ValidFrom]
,[ValidTo]
FROM [HumanResources].[Employee_Temporal]
GO
SELECT [BusinessEntityID]
,[DepartmentID]
,[ShiftID]
,[StartDate]
,[EndDate]
,[ModifiedDate]
FROM [HumanResources].[EmployeeDepartmentHistory]
GO
SELECT [BusinessEntityID]
,[RateChangeDate]
,[Rate]
,[PayFrequency]
,[ModifiedDate]
FROM [HumanResources].[EmployeePayHistory]
GO
SELECT [JobCandidateID]
,[BusinessEntityID]
,[Resume]
,[ModifiedDate]
FROM [HumanResources].[JobCandidate]
GO
SELECT [ShiftID]
,[Name]
,[StartTime]
,[EndTime]
,[ModifiedDate]
FROM [HumanResources].[Shift]
GO

View File

@@ -0,0 +1,13 @@
USE master
GO
DECLARE @dbname nvarchar(128)
SET @dbname = N'#DatabaseName#'
IF NOT(EXISTS (SELECT name
FROM master.dbo.sysdatabases
WHERE ('[' + name + ']' = @dbname
OR name = @dbname)))
BEGIN
CREATE DATABASE #DatabaseName#
END

View File

@@ -0,0 +1,231 @@
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Demo')
BEGIN
EXEC('CREATE SCHEMA [Demo]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'HumanResources')
BEGIN
EXEC('CREATE SCHEMA [HumanResources]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Person')
BEGIN
EXEC('CREATE SCHEMA [Person]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Production')
BEGIN
EXEC('CREATE SCHEMA [Production]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Purchasing')
BEGIN
EXEC('CREATE SCHEMA [Purchasing]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Sales')
BEGIN
EXEC('CREATE SCHEMA [Sales]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = 'Security')
BEGIN
EXEC('CREATE SCHEMA [Security]')
END
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'AccountNumber')
BEGIN
CREATE TYPE [dbo].[AccountNumber] FROM [nvarchar](15) NULL
END
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Flag')
BEGIN
CREATE TYPE [dbo].[Flag] FROM [bit] NOT NULL
END
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Name')
BEGIN
CREATE TYPE [dbo].[Name] FROM [nvarchar](50) NULL
END
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'NameStyle')
BEGIN
CREATE TYPE [dbo].[NameStyle] FROM [bit] NOT NULL
END
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'OrderNumber')
BEGIN
CREATE TYPE [dbo].[OrderNumber] FROM [nvarchar](25) NULL
END
GO
GO
IF NOT EXISTS (SELECT * FROM sys.types WHERE name = 'Phone')
BEGIN
CREATE TYPE [dbo].[Phone] FROM [nvarchar](25) NULL
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Address')
BEGIN
CREATE TABLE [Person].[Address](
[AddressID] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[AddressLine1] [nvarchar](60) NOT NULL,
[AddressLine2] [nvarchar](60) NULL,
[City] [nvarchar](30) NOT NULL,
[StateProvinceID] [int] NOT NULL,
[PostalCode] [nvarchar](15) NOT NULL,
[SpatialLocation] [geography] NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_Address_AddressID] PRIMARY KEY CLUSTERED
(
[AddressID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'AddressType')
BEGIN
CREATE TABLE [Person].[AddressType](
[AddressTypeID] [int] IDENTITY(1,1) NOT NULL,
[Name] [dbo].[Name] NOT NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_AddressType_AddressTypeID] PRIMARY KEY CLUSTERED
(
[AddressTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object: Table [Person].[ContactType] Script Date: 11/22/2016 9:25:52 AM ******/
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'ContactType')
BEGIN
CREATE TABLE [Person].[ContactType](
[ContactTypeID] [int] IDENTITY(1,1) NOT NULL,
[Name] [dbo].[Name] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_ContactType_ContactTypeID] PRIMARY KEY CLUSTERED
(
[ContactTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'EmailAddress')
BEGIN
CREATE TABLE [Person].[EmailAddress](
[BusinessEntityID] [int] NOT NULL,
[EmailAddressID] [int] IDENTITY(1,1) NOT NULL,
[EmailAddress] [nvarchar](50) NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_EmailAddress_BusinessEntityID_EmailAddressID] PRIMARY KEY CLUSTERED
(
[BusinessEntityID] ASC,
[EmailAddressID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Person')
BEGIN
CREATE TABLE [Person].[Person](
[BusinessEntityID] [int] NOT NULL,
[PersonType] [nchar](2) NOT NULL,
[NameStyle] [dbo].[NameStyle] NOT NULL,
[Title] [nvarchar](8) NULL,
[FirstName] [dbo].[Name] NOT NULL,
[MiddleName] [dbo].[Name] NULL,
[LastName] [dbo].[Name] NOT NULL,
[Suffix] [nvarchar](10) NULL,
[EmailPromotion] [int] NOT NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_Person_BusinessEntityID] PRIMARY KEY CLUSTERED
(
[BusinessEntityID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'PersonPhone')
BEGIN
CREATE TABLE [Person].[PersonPhone](
[BusinessEntityID] [int] NOT NULL,
[PhoneNumber] [dbo].[Phone] NOT NULL,
[PhoneNumberTypeID] [int] NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_PersonPhone_BusinessEntityID_PhoneNumber_PhoneNumberTypeID] PRIMARY KEY CLUSTERED
(
[BusinessEntityID] ASC,
[PhoneNumber] ASC,
[PhoneNumberTypeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Location')
BEGIN
CREATE TABLE [Production].[Location](
[LocationID] [smallint] IDENTITY(1,1) NOT NULL,
[Name] [dbo].[Name] NOT NULL,
[CostRate] [smallmoney] NOT NULL,
[Availability] [decimal](8, 2) NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_Location_LocationID] PRIMARY KEY CLUSTERED
(
[LocationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Product')
BEGIN
CREATE TABLE [Production].[Product](
[ProductID] [int] IDENTITY(1,1) NOT NULL,
[Name] [dbo].[Name] NOT NULL,
[ProductNumber] [nvarchar](25) NOT NULL,
[MakeFlag] [dbo].[Flag] NOT NULL,
[FinishedGoodsFlag] [dbo].[Flag] NOT NULL,
[Color] [nvarchar](15) NULL,
[SafetyStockLevel] [smallint] NOT NULL,
[ReorderPoint] [smallint] NOT NULL,
[StandardCost] [money] NOT NULL,
[ListPrice] [money] NOT NULL,
[Size] [nvarchar](5) NULL,
[SizeUnitMeasureCode] [nchar](3) NULL,
[WeightUnitMeasureCode] [nchar](3) NULL,
[Weight] [decimal](8, 2) NULL,
[DaysToManufacture] [int] NOT NULL,
[ProductLine] [nchar](2) NULL,
[Class] [nchar](2) NULL,
[Style] [nchar](2) NULL,
[ProductSubcategoryID] [int] NULL,
[ProductModelID] [int] NULL,
[SellStartDate] [datetime] NOT NULL,
[SellEndDate] [datetime] NULL,
[DiscontinuedDate] [datetime] NULL,
[rowguid] [uniqueidentifier] ROWGUIDCOL NOT NULL,
[ModifiedDate] [datetime] NOT NULL,
CONSTRAINT [PK_Product_ProductID] PRIMARY KEY CLUSTERED
(
[ProductID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO

View File

@@ -11,27 +11,55 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts
{ {
public class Scripts public class Scripts
{ {
public const string MasterBasicQuery = "SELECT * FROM sys.all_columns"; //basic queries should return at least 10000 rows
public const string SimpleQuery = "SELECT * FROM sys.all_columns";
public const string DelayQuery = "WAITFOR DELAY '00:01:00'"; public const string DelayQuery = "WAITFOR DELAY '00:01:00'";
private static readonly Lazy<string> ComplexQueryInstance = new Lazy<string>(() => public const string TestDbSimpleSelectQuery = "SELECT * FROM [Person].[Address]";
public const string SelectQuery = "SELECT * FROM ";
public static string CreateDatabaseObjectsQuery { get { return CreateDatabaseObjectsQueryInstance.Value; } }
public static string CreateDatabaseQuery { get { return CreateDatabaseQueryInstance.Value; } }
public static string TestDbComplexSelectQueries { get { return TestDbSelectQueriesInstance.Value; } }
private static readonly Lazy<string> CreateDatabaseObjectsQueryInstance = new Lazy<string>(() =>
{ {
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabaseObjects.sql");
});
private static readonly Lazy<string> CreateDatabaseQueryInstance = new Lazy<string>(() =>
{
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabase.sql");
});
private static readonly Lazy<string> TestDbSelectQueriesInstance = new Lazy<string>(() =>
{
return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.TestDbTableQueries.sql");
});
private static string GetScriptFileContent(string fileName)
{
string fileContent = string.Empty;
try try
{ {
string assemblyLocation = typeof(Scripts).GetTypeInfo().Assembly.Location; using (Stream stream = typeof(Scripts).GetTypeInfo().Assembly.GetManifestResourceStream(fileName))
string folderName = Path.GetDirectoryName(assemblyLocation); {
string filePath = Path.Combine(folderName, "Scripts/AdventureWorks.sql"); using (StreamReader reader = new StreamReader(stream))
return File.ReadAllText(filePath); {
fileContent = reader.ReadToEnd();
}
}
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"Failed to load the sql script. error: {ex.Message}"); Console.WriteLine($"Failed to load the sql script. error: {ex.Message}");
return string.Empty;
} }
}); return fileContent;
}
public static string ComplexQuery { get { return ComplexQueryInstance.Value; } }
} }
} }

View File

@@ -0,0 +1,84 @@
SELECT * FROM [Person].[Address]
SELECT [AddressID]
,[AddressLine1]
,[AddressLine2]
,[City]
,[StateProvinceID]
,[PostalCode]
,[SpatialLocation]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Address]
GO
SELECT [AddressTypeID]
,[Name]
,[rowguid]
,[ModifiedDate]
FROM [Person].[AddressType]
GO
SELECT [ContactTypeID]
,[Name]
,[ModifiedDate]
FROM [Person].[ContactType]
GO
SELECT [BusinessEntityID]
,[EmailAddressID]
,[EmailAddress]
,[rowguid]
,[ModifiedDate]
FROM [Person].[EmailAddress]
GO
SELECT [BusinessEntityID]
,[PersonType]
,[NameStyle]
,[Title]
,[FirstName]
,[MiddleName]
,[LastName]
,[Suffix]
,[EmailPromotion]
,[rowguid]
,[ModifiedDate]
FROM [Person].[Person]
GO
SELECT [BusinessEntityID]
,[PhoneNumber]
,[PhoneNumberTypeID]
,[ModifiedDate]
FROM [Person].[PersonPhone]
GO
SELECT [LocationID]
,[Name]
,[CostRate]
,[Availability]
,[ModifiedDate]
FROM [Production].[Location]
GO
SELECT [ProductID]
,[Name]
,[ProductNumber]
,[MakeFlag]
,[FinishedGoodsFlag]
,[Color]
,[SafetyStockLevel]
,[ReorderPoint]
,[StandardCost]
,[ListPrice]
,[Size]
,[SizeUnitMeasureCode]
,[WeightUnitMeasureCode]
,[Weight]
,[DaysToManufacture]
,[ProductLine]
,[Class]
,[Style]
,[ProductSubcategoryID]
,[ProductModelID]
,[SellStartDate]
,[SellEndDate]
,[DiscontinuedDate]
,[rowguid]
,[ModifiedDate]
FROM [Production].[Product]
GO

View File

@@ -172,7 +172,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
/// <summary> /// <summary>
/// Returns database connection parameters for given server type /// Returns database connection parameters for given server type
/// </summary> /// </summary>
public async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType) public async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType, string databaseName)
{ {
ConnectionProfile connectionProfile = null; ConnectionProfile connectionProfile = null;
TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType); TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType);
@@ -195,6 +195,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
} }
ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database, ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database,
connectionProfile.User, password); connectionProfile.User, password);
if (!string.IsNullOrEmpty(databaseName))
{
conenctParam.Connection.DatabaseName = databaseName;
}
if (serverType == TestServerType.Azure)
{
conenctParam.Connection.ConnectTimeout = 30;
conenctParam.Connection.Encrypt = true;
conenctParam.Connection.TrustServerCertificate = false;
}
return conenctParam; return conenctParam;
} }
return null; return null;

View File

@@ -41,6 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Failed to load the database connection server name settings. error: " + ex.Message);
return null; return null;
} }
} }
@@ -56,6 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Failed to load the connection settings. error: " + ex.Message);
return null; return null;
} }
} }

View File

@@ -4,10 +4,12 @@
// //
using System; using System;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Xunit; using Xunit;
using Xunit.Sdk;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{ {
@@ -23,27 +25,33 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
bool containsTestName = testName.Contains("."); bool containsTestName = testName.Contains(".");
var className = containsTestName ? testName.Substring(0, testName.LastIndexOf('.')) : testName; var className = containsTestName ? testName.Substring(0, testName.LastIndexOf('.')) : testName;
var methodName = containsTestName ? testName.Substring(testName.LastIndexOf('.') + 1) : null; var methodName = containsTestName ? testName.Substring(testName.LastIndexOf('.') + 1) : null;
Assembly assembly = Assembly.GetEntryAssembly();
Type type = assembly.GetType(testNamespace + className);
var type = Type.GetType(testNamespace + className);
if (type == null) if (type == null)
{ {
Console.WriteLine("Invalid class name"); Console.WriteLine("Invalid class name");
} }
else else
{ {
var typeInstance = Activator.CreateInstance(type);
if (string.IsNullOrEmpty(methodName)) if (string.IsNullOrEmpty(methodName))
{ {
var methods = type.GetMethods().Where(x => x.CustomAttributes.Any(a => a.AttributeType == typeof(FactAttribute))); var methods = type.GetMethods().Where(x => x.CustomAttributes.Any(a => a.AttributeType == typeof(FactAttribute)));
foreach (var method in methods) foreach (var method in methods)
{ {
await RunTest(type, method, method.Name); await RunTest(typeInstance, method, method.Name);
} }
} }
else else
{ {
MethodInfo methodInfo = type.GetMethod(methodName); MethodInfo methodInfo = type.GetMethod(methodName);
await RunTest(type, methodInfo, test); await RunTest(typeInstance, methodInfo, test);
}
IDisposable disposable = typeInstance as IDisposable;
if (disposable != null)
{
disposable.Dispose();
} }
} }
} }
@@ -56,21 +64,43 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
return 0; return 0;
} }
private static async Task RunTest(Type type, MethodBase methodInfo, string testName) private static async Task RunTest(object typeInstance, MethodInfo methodInfo, string testName)
{ {
if (methodInfo == null) try
{ {
Console.WriteLine("Invalid method name"); if (methodInfo == null)
}
else
{
using (var typeInstance = (IDisposable)Activator.CreateInstance(type))
{ {
Console.WriteLine("Invalid method name");
}
else
{
var testAttributes = methodInfo.CustomAttributes;
BeforeAfterTestAttribute beforeAfterTestAttribute = null;
foreach (var attribute in testAttributes)
{
var args = attribute.ConstructorArguments.Select(x => x.Value as object).ToArray();
var objAttribute = Activator.CreateInstance(attribute.AttributeType, args);
beforeAfterTestAttribute = objAttribute as BeforeAfterTestAttribute;
if (beforeAfterTestAttribute != null)
{
beforeAfterTestAttribute.Before(methodInfo);
}
}
Console.WriteLine("Running test " + testName); Console.WriteLine("Running test " + testName);
await (Task)methodInfo.Invoke(typeInstance, null); await (Task)methodInfo.Invoke(typeInstance, null);
if (beforeAfterTestAttribute != null)
{
beforeAfterTestAttribute.After(methodInfo);
}
Console.WriteLine("Test ran successfully: " + testName); Console.WriteLine("Test ran successfully: " + testName);
} }
} }
catch(Exception ex)
{
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Failed: {0} error: {1}", testName, ex.Message));
}
} }
} }
} }

View File

@@ -17,7 +17,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{ {
private static string resultFolder = InitResultFolder(); private static string resultFolder = InitResultFolder();
private static string InitResultFolder() private static string InitResultFolder()
{ {
string resultFodler = Environment.GetEnvironmentVariable("ResultFolder"); string resultFodler = Environment.GetEnvironmentVariable("ResultFolder");
@@ -34,6 +33,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
Start(); Start();
} }
public bool PrintResult { get; set; }
public void Start() public void Start()
{ {
StartDateTime = DateTime.UtcNow; StartDateTime = DateTime.UtcNow;
@@ -47,15 +48,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
public void EndAndPrint([CallerMemberName] string testName = "") public void EndAndPrint([CallerMemberName] string testName = "")
{ {
End(); End();
var currentColor = Console.ForegroundColor; if (PrintResult)
Console.ForegroundColor = ConsoleColor.Green; {
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds)); var currentColor = Console.ForegroundColor;
Console.ForegroundColor = currentColor; Console.ForegroundColor = ConsoleColor.Green;
string resultContent = Newtonsoft.Json.JsonConvert.SerializeObject(new TestResult { ElapsedTime = TotalMilliSeconds }); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
string fileName = testName + ".json"; Console.ForegroundColor = currentColor;
string resultFilePath = string.IsNullOrEmpty(resultFolder) ? fileName : Path.Combine(resultFolder, fileName); string resultContent = Newtonsoft.Json.JsonConvert.SerializeObject(new TestResult { ElapsedTime = TotalMilliSeconds });
File.WriteAllText(resultFilePath, resultContent); string fileName = testName + ".json";
Console.WriteLine("Result file: " + resultFilePath); string resultFilePath = string.IsNullOrEmpty(resultFolder) ? fileName : Path.Combine(resultFolder, fileName);
File.WriteAllText(resultFilePath, resultContent);
Console.WriteLine("Result file: " + resultFilePath);
}
} }
public double TotalMilliSeconds public double TotalMilliSeconds

View File

@@ -4,9 +4,11 @@
"buildOptions": { "buildOptions": {
"debugType": "portable", "debugType": "portable",
"emitEntryPoint": true, "emitEntryPoint": true,
"copyToOutput": { "embed": {
"includeFiles": [ "includeFiles": [
"Scripts/AdventureWorks.sql" "Scripts/CreateTestDatabaseObjects.sql",
"Scripts/CreateTestDatabase.sql",
"Scripts/TestDbTableQueries.sql"
] ]
}, },
"publishOptions": { "publishOptions": {
@@ -27,6 +29,7 @@
"netcoreapp1.0": { "netcoreapp1.0": {
"dependencies": { "dependencies": {
"Microsoft.NETCore.App": { "Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0" "version": "1.0.0"
} }
}, },