diff --git a/RefreshDllsForTestRun.cmd b/RefreshDllsForTestRun.cmd
new file mode 100644
index 00000000..284f4aa1
--- /dev/null
+++ b/RefreshDllsForTestRun.cmd
@@ -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"
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/CreateTestDbAttribute.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/CreateTestDbAttribute.cs
new file mode 100644
index 00000000..2b705918
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/CreateTestDbAttribute.cs
@@ -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
+{
+ ///
+ /// The attribute for each test to create the test db before the test starts
+ ///
+ 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)
+ {
+ }
+ }
+}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs
index aa2dc482..0d920084 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Program.cs
@@ -25,7 +25,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests
Logger.Initialize("testdriver", LogLevel.Verbose);
- return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.Tests.").Result;
+ return TestRunner.RunTests(args, "Microsoft.SqlTools.ServiceLayer.PerfTests.").Result;
}
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/Common.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/Common.cs
index 0011d226..7b8c8985 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/Common.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/Common.cs
@@ -4,18 +4,24 @@
//
using System;
+using System.Globalization;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
+using Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
+namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
public class Common
{
+ public const string PerfTestDatabaseName = "SQLToolsCrossPlatPerfTestDb";
+ public const string MasterDatabaseName = "master";
+
+
internal static async Task ExecuteWithTimeout(TestTimer timer, int timeout, Func> repeatedCode,
TimeSpan? delay = null, [CallerMemberName] string testName = "")
{
@@ -38,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
}
}
- internal static async Task ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri)
+ internal static async Task ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri, string databaseName)
{
testHelper.WriteToFile(ownerUri, query);
@@ -56,7 +62,8 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
await testHelper.RequestOpenDocumentNotification(openParams);
Thread.Sleep(500);
- var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType);
+ var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, databaseName);
+
bool connected = await testHelper.Connect(ownerUri, connectParams);
Assert.True(connected, "Connection is successful");
Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");
@@ -64,13 +71,41 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
return connected;
}
- internal static async Task CalculateRunTime(Func> testToRun, [CallerMemberName] string testName = "")
+ internal static async Task CalculateRunTime(Func> testToRun, bool printResult, [CallerMemberName] string testName = "")
{
- TestTimer timer = new TestTimer();
+ TestTimer timer = new TestTimer() { PrintResult = printResult };
T result = await testToRun();
timer.EndAndPrint(testName);
return result;
}
+
+ ///
+ /// Create the test db if not already exists
+ ///
+ 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);
+ }
+ }
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/ConnectionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/ConnectionTests.cs
index a5edd3d5..44cc0be7 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/ConnectionTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/ConnectionTests.cs
@@ -11,18 +11,20 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
+namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
public class ConnectionTests
{
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task ConnectAzureTest()
{
+ TestServerType serverType = TestServerType.Azure;
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- const string query = Scripts.SimpleQuery;
+ const string query = Scripts.TestDbSimpleSelectQuery;
testHelper.WriteToFile(queryTempFile.FilePath, query);
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
@@ -41,20 +43,23 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
Thread.Sleep(500);
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);
- });
+ }, true);
Assert.True(connected, "Connection was not successful");
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task ConnectOnPremTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- const string query = Scripts.SimpleQuery;
+ const string query = Scripts.TestDbSimpleSelectQuery;
testHelper.WriteToFile(queryTempFile.FilePath, query);
DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
@@ -73,22 +78,25 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
Thread.Sleep(500);
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);
- });
+ }, true);
Assert.True(connected, "Connection was not successful");
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task DisconnectTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
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);
- var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath));
+ var connected = await Common.CalculateRunTime(() => testHelper.Disconnect(queryTempFile.FilePath), true);
Assert.True(connected);
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs
index 642007c5..cffe764c 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/IntellisenseTests.cs
@@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
+using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
@@ -14,45 +15,53 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
+namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
public class IntellisenseTests
{
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task HoverTestOnPrem()
{
- using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
+ TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper())
+ using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
- const string query = Scripts.SimpleQuery;
- await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
- Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, 15));
+ const string query = Scripts.TestDbSimpleSelectQuery;
+ await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
+ Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, Scripts.TestDbComplexSelectQueries.Length + 1), true);
Assert.NotNull(hover);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task SuggestionsTest()
{
- using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
+ TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper())
+ using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
- const string query = Scripts.SimpleQuery;
- await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
- await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query, null);
- await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, query);
+ const string query = Scripts.TestDbSimpleSelectQuery;
+ await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
+ await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, false, Common.PerfTestDatabaseName, true);
+ await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, true, Common.PerfTestDatabaseName, false);
await testHelper.Disconnect(queryTempFile.FilePath);
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task DiagnosticsTests()
{
- using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
+ TestServerType serverType = TestServerType.OnPrem;
+ await Common.CreateTestDatabase(serverType);
+
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);
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 Common.ExecuteWithTimeout(timer, 60000, async () =>
{
@@ -96,118 +105,172 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
}
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdAzureSimpleQuery()
{
+ TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper())
{
- await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.SimpleQuery);
+ await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, false);
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheColdOnPremSimpleQuery()
{
+ TestServerType serverType = TestServerType.OnPrem;
using (TestHelper testHelper = new TestHelper())
{
- await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.SimpleQuery);
+ await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbSimpleSelectQuery, false);
}
+
}
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheWarmAzureSimpleQuery()
{
+ TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
- const string query = Scripts.SimpleQuery;
- const TestServerType serverType = TestServerType.Azure;
- await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
- Thread.Sleep(10000);
- await VerifyBindingLoadScenario(testHelper, serverType, query);
+ const string query = Scripts.TestDbSimpleSelectQuery;
+ await VerifyBindingLoadScenario(testHelper, serverType, query, true);
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheWarmOnPremSimpleQuery()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (TestHelper testHelper = new TestHelper())
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
- const string query = Scripts.SimpleQuery;
- const TestServerType serverType = TestServerType.OnPrem;
- await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
- Thread.Sleep(10000);
- await VerifyBindingLoadScenario(testHelper, serverType, query);
+ const string query = Scripts.TestDbSimpleSelectQuery;
+ await VerifyBindingLoadScenario(testHelper, serverType, query, true);
}
}
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdAzureComplexQuery()
{
+ TestServerType serverType = TestServerType.Azure;
+
using (TestHelper testHelper = new TestHelper())
{
- await VerifyBindingLoadScenario(testHelper, TestServerType.Azure, Scripts.ComplexQuery);
+ await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbComplexSelectQueries,false);
}
}
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheColdOnPremComplexQuery()
{
+ TestServerType serverType = TestServerType.Azure;
using (TestHelper testHelper = new TestHelper())
{
- await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.ComplexQuery);
+ await VerifyBindingLoadScenario(testHelper, TestServerType.OnPrem, Scripts.TestDbComplexSelectQueries, false);
}
}
[Fact]
+ [CreateTestDb(TestServerType.Azure)]
public async Task BindingCacheWarmAzureComplexQuery()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- string query = Scripts.ComplexQuery;
+ string query = Scripts.TestDbComplexSelectQueries;
const TestServerType serverType = TestServerType.Azure;
- await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
- Thread.Sleep(10000);
- await VerifyBindingLoadScenario(testHelper, serverType, query);
+ await VerifyBindingLoadScenario(testHelper, serverType, query, true);
}
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task BindingCacheWarmOnPremComplexQuery()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- string query = Scripts.ComplexQuery;
+ string query = Scripts.TestDbComplexSelectQueries;
const TestServerType serverType = TestServerType.OnPrem;
- await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath);
- Thread.Sleep(10000);
- await VerifyBindingLoadScenario(testHelper, serverType, query);
+ await VerifyBindingLoadScenario(testHelper, serverType, query, true);
}
}
#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);
- await Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath);
- await ValidateCompletionResponse(testHelper, testTempFile.FilePath, query, testName);
+ await Common.ConnectAsync(testHelper, serverType, query, testTempFile.FilePath, databaseName);
+ await ValidateCompletionResponse(testHelper, testTempFile.FilePath, printResult, databaseName,
+ waitForIntelliSense: true, testName: testName);
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();
- await Common.ExecuteWithTimeout(timer, 60000, async () =>
+ TestTimer timer = new TestTimer() { PrintResult = printResult };
+ bool isReady = !waitForIntelliSense;
+ await Common.ExecuteWithTimeout(timer, 150000, async () =>
{
- CompletionItem[] completions = await testHelper.RequestCompletion(ownerUri, query, 0, 15);
- return completions != null && completions.Any(x => x.Label == "master");
- }, testName:testName);
- }
+ if (isReady)
+ {
+ 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
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/QueryExecutionTests.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/QueryExecutionTests.cs
index 1b8ff999..8d41cd1e 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/QueryExecutionTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/QueryExecutionTests.cs
@@ -12,20 +12,22 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
+namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
public class QueryExecutionTests
{
[Fact]
public async Task QueryResultSummaryOnPremTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- const string query = Scripts.SimpleQuery;
+ const string query = Scripts.MasterBasicQuery;
- await Common.ConnectAsync(testHelper, TestServerType.OnPrem, query, queryTempFile.FilePath);
- var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query));
+ await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.MasterDatabaseName);
+ var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query), true);
Assert.NotNull(queryResult);
Assert.True(queryResult.BatchSummaries.Any(x => x.ResultSetSummaries.Any(r => r.RowCount > 0)));
@@ -37,18 +39,20 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
[Fact]
public async Task QueryResultFirstOnPremTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
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 () =>
{
await testHelper.RunQuery(queryTempFile.FilePath, query);
return await testHelper.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 100);
- });
+ }, true);
Assert.NotNull(queryResult);
Assert.NotNull(queryResult.ResultSubset);
@@ -59,12 +63,15 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
}
[Fact]
+ [CreateTestDb(TestServerType.OnPrem)]
public async Task CancelQueryOnPremTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
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
{
OwnerUri = queryTempFile.FilePath,
@@ -74,9 +81,12 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
var result = await testHelper.Driver.SendRequest(QueryExecuteRequest.Type, queryParams);
if (result != null && string.IsNullOrEmpty(result.Messages))
{
- TestTimer timer = new TestTimer();
- await Common.ExecuteWithTimeout(timer, 100000,
- async () => await testHelper.CancelConnect(queryTempFile.FilePath), TimeSpan.FromMilliseconds(10));
+ TestTimer timer = new TestTimer() { PrintResult = true };
+ await Common.ExecuteWithTimeout(timer, 100000, async () =>
+ {
+ var cancelQueryResult = await testHelper.CancelQuery(queryTempFile.FilePath);
+ return true;
+ }, TimeSpan.FromMilliseconds(10));
}
else
{
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/SaveResultsTests.cs b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/SaveResultsTests.cs
index adc0e7a9..298d325e 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/SaveResultsTests.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/Tests/SaveResultsTests.cs
@@ -9,23 +9,25 @@ using Microsoft.SqlTools.ServiceLayer.TestDriver.Tests;
using Microsoft.SqlTools.ServiceLayer.TestDriver.Utility;
using Xunit;
-namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
+namespace Microsoft.SqlTools.ServiceLayer.PerfTests
{
public class SaveResultsTests
{
[Fact]
public async Task TestSaveResultsToCsvTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- const string query = Scripts.SimpleQuery;
+ const string query = Scripts.MasterBasicQuery;
// 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 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);
}
}
@@ -33,17 +35,18 @@ namespace Microsoft.SqlTools.ServiceLayer.PerfTests.Tests
[Fact]
public async Task TestSaveResultsToJsonTest()
{
+ TestServerType serverType = TestServerType.OnPrem;
+
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
using (SelfCleaningTempFile outputTempFile = new SelfCleaningTempFile())
using (TestHelper testHelper = new TestHelper())
{
- const string query = Scripts.SimpleQuery;
- const TestServerType serverType = TestServerType.OnPrem;
+ const string query = Scripts.MasterBasicQuery;
// 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 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);
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json
index abb50518..4eb7c6fd 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json
+++ b/test/Microsoft.SqlTools.ServiceLayer.PerfTests/project.json
@@ -1,14 +1,18 @@
{
+ "name": "Microsoft.SqlTools.ServiceLayer.PerfTests",
"version": "1.0.0-*",
-
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": true
+ },
"dependencies": {
- "xunit": "2.1.0",
+ "xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-192208-24",
"Microsoft.SqlTools.ServiceLayer": {
"target": "project"
},
- "Microsoft.SqlTools.ServiceLayer.TestDriver": "1.0.0-*"
- },
+ "Microsoft.SqlTools.ServiceLayer.TestDriver": "1.0.0-*"
+ },
"testRunner": "xunit",
@@ -16,14 +20,16 @@
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
- "type": "platform",
- "version" : "1.0.0"
- }
+ "version": "1.0.0"
+ }
},
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
+ },
+ "runtimes": {
+ "win7-x64": {}
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/AdventureWorks.sql b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/AdventureWorks.sql
deleted file mode 100644
index fa6b46da..00000000
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/AdventureWorks.sql
+++ /dev/null
@@ -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
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabase.sql b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabase.sql
new file mode 100644
index 00000000..58e4cd19
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabase.sql
@@ -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
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabaseObjects.sql b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabaseObjects.sql
new file mode 100644
index 00000000..f815c4f7
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/CreateTestDatabaseObjects.sql
@@ -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
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/Scripts.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/Scripts.cs
index f2c28877..02aa695e 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/Scripts.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/Scripts.cs
@@ -11,27 +11,55 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts
{
public class Scripts
{
-
- public const string SimpleQuery = "SELECT * FROM sys.all_columns";
+ public const string MasterBasicQuery = "SELECT * FROM sys.all_columns"; //basic queries should return at least 10000 rows
public const string DelayQuery = "WAITFOR DELAY '00:01:00'";
- private static readonly Lazy ComplexQueryInstance = new Lazy(() =>
+ 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 CreateDatabaseObjectsQueryInstance = new Lazy(() =>
{
+ return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabaseObjects.sql");
+ });
+
+ private static readonly Lazy CreateDatabaseQueryInstance = new Lazy(() =>
+ {
+ return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.CreateTestDatabase.sql");
+ });
+
+ private static readonly Lazy TestDbSelectQueriesInstance = new Lazy(() =>
+ {
+ return GetScriptFileContent("Microsoft.SqlTools.ServiceLayer.TestDriver.Scripts.TestDbTableQueries.sql");
+ });
+
+ private static string GetScriptFileContent(string fileName)
+ {
+ string fileContent = string.Empty;
try
{
- string assemblyLocation = typeof(Scripts).GetTypeInfo().Assembly.Location;
- string folderName = Path.GetDirectoryName(assemblyLocation);
- string filePath = Path.Combine(folderName, "Scripts/AdventureWorks.sql");
- return File.ReadAllText(filePath);
+ using (Stream stream = typeof(Scripts).GetTypeInfo().Assembly.GetManifestResourceStream(fileName))
+ {
+ using (StreamReader reader = new StreamReader(stream))
+ {
+ fileContent = reader.ReadToEnd();
+ }
+ }
}
catch (Exception ex)
{
Console.WriteLine($"Failed to load the sql script. error: {ex.Message}");
- return string.Empty;
}
- });
+ return fileContent;
+ }
- public static string ComplexQuery { get { return ComplexQueryInstance.Value; } }
+
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/TestDbTableQueries.sql b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/TestDbTableQueries.sql
new file mode 100644
index 00000000..2ce30a44
--- /dev/null
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Scripts/TestDbTableQueries.sql
@@ -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
\ No newline at end of file
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestHelper.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestHelper.cs
index 3f3906a2..54d2690b 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestHelper.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestHelper.cs
@@ -172,7 +172,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
///
/// Returns database connection parameters for given server type
///
- public async Task GetDatabaseConnectionAsync(TestServerType serverType)
+ public async Task GetDatabaseConnectionAsync(TestServerType serverType, string databaseName)
{
ConnectionProfile connectionProfile = null;
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,
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 null;
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs
index 005607aa..273f8f22 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs
@@ -41,6 +41,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
}
catch (Exception ex)
{
+ Console.WriteLine("Failed to load the database connection server name settings. error: " + ex.Message);
return null;
}
}
@@ -56,6 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
}
catch (Exception ex)
{
+ Console.WriteLine("Failed to load the connection settings. error: " + ex.Message);
return null;
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestRunner.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestRunner.cs
index a3b6fc61..e0f443b1 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestRunner.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestRunner.cs
@@ -4,10 +4,12 @@
//
using System;
+using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit;
+using Xunit.Sdk;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{
@@ -23,27 +25,33 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
bool containsTestName = testName.Contains(".");
var className = containsTestName ? testName.Substring(0, testName.LastIndexOf('.')) : testName;
var methodName = containsTestName ? testName.Substring(testName.LastIndexOf('.') + 1) : null;
-
-
- var type = Type.GetType(testNamespace + className);
+ Assembly assembly = Assembly.GetEntryAssembly();
+ Type type = assembly.GetType(testNamespace + className);
if (type == null)
{
Console.WriteLine("Invalid class name");
}
else
{
+ var typeInstance = Activator.CreateInstance(type);
if (string.IsNullOrEmpty(methodName))
{
var methods = type.GetMethods().Where(x => x.CustomAttributes.Any(a => a.AttributeType == typeof(FactAttribute)));
foreach (var method in methods)
{
- await RunTest(type, method, method.Name);
+ await RunTest(typeInstance, method, method.Name);
}
}
else
{
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;
}
- 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");
- }
- else
- {
- using (var typeInstance = (IDisposable)Activator.CreateInstance(type))
+ if (methodInfo == null)
{
+ 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);
await (Task)methodInfo.Invoke(typeInstance, null);
+ if (beforeAfterTestAttribute != null)
+ {
+ beforeAfterTestAttribute.After(methodInfo);
+ }
Console.WriteLine("Test ran successfully: " + testName);
}
}
+ catch(Exception ex)
+ {
+ Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Failed: {0} error: {1}", testName, ex.Message));
+
+ }
}
}
}
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs
index 3bba40c6..05e4c00f 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs
@@ -17,7 +17,6 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{
private static string resultFolder = InitResultFolder();
-
private static string InitResultFolder()
{
string resultFodler = Environment.GetEnvironmentVariable("ResultFolder");
@@ -34,6 +33,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
Start();
}
+ public bool PrintResult { get; set; }
+
public void Start()
{
StartDateTime = DateTime.UtcNow;
@@ -47,15 +48,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
public void EndAndPrint([CallerMemberName] string testName = "")
{
End();
- var currentColor = Console.ForegroundColor;
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
- Console.ForegroundColor = currentColor;
- string resultContent = Newtonsoft.Json.JsonConvert.SerializeObject(new TestResult { ElapsedTime = TotalMilliSeconds });
- string fileName = testName + ".json";
- string resultFilePath = string.IsNullOrEmpty(resultFolder) ? fileName : Path.Combine(resultFolder, fileName);
- File.WriteAllText(resultFilePath, resultContent);
- Console.WriteLine("Result file: " + resultFilePath);
+ if (PrintResult)
+ {
+ var currentColor = Console.ForegroundColor;
+ Console.ForegroundColor = ConsoleColor.Green;
+ Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
+ Console.ForegroundColor = currentColor;
+ string resultContent = Newtonsoft.Json.JsonConvert.SerializeObject(new TestResult { ElapsedTime = TotalMilliSeconds });
+ string fileName = testName + ".json";
+ string resultFilePath = string.IsNullOrEmpty(resultFolder) ? fileName : Path.Combine(resultFolder, fileName);
+ File.WriteAllText(resultFilePath, resultContent);
+ Console.WriteLine("Result file: " + resultFilePath);
+ }
}
public double TotalMilliSeconds
diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/project.json b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/project.json
index 60eafd43..71f0ce7a 100644
--- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/project.json
+++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/project.json
@@ -4,9 +4,11 @@
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
- "copyToOutput": {
+ "embed": {
"includeFiles": [
- "Scripts/AdventureWorks.sql"
+ "Scripts/CreateTestDatabaseObjects.sql",
+ "Scripts/CreateTestDatabase.sql",
+ "Scripts/TestDbTableQueries.sql"
]
},
"publishOptions": {
@@ -27,6 +29,7 @@
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
+ "type": "platform",
"version": "1.0.0"
}
},