diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/PerformanceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/PerformanceTests.cs index 77007069..9e17cd76 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/PerformanceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/PerformanceTests.cs @@ -18,9 +18,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests { public class PerformanceTests : TestBase { - private static string ComplexQuery = File.ReadAllText("./Scripts/AdventureWorks.sql"); + private static string ComplexQuery = LoadComplexScript(); private static string SimpleQuery = "SELECT * FROM sys.all_columns"; + + private static string LoadComplexScript() + { + string assemblyLocation = System.Reflection.Assembly.GetEntryAssembly().Location; + string folderName = Path.GetDirectoryName(assemblyLocation); + string filePath = Path.Combine(folderName, "Scripts/AdventureWorks.sql"); + return File.ReadAllText(filePath); + } + [Fact] public async Task HoverTestOnPrem() { @@ -556,6 +565,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests TestTimer timer = new TestTimer(); T result = await testToRun(); timer.EndAndPrint(testName); + + return result; } } diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs index bfff905c..5d424107 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Tests/TestBase.cs @@ -183,12 +183,32 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests /// protected async Task GetDatabaseConnectionAsync(TestServerType serverType) { + ConnectionProfile connectionProfile = null; TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType); - var connectionProfile = ConnectionTestUtils.Setting.GetConnentProfile(serverIdentiry.ProfileName, serverIdentiry.ServerName); - Credential credential = await ReadCredential(connectionProfile.formatCredentialId()); - ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database, - connectionProfile.User, credential.Password); - return conenctParam; + if (serverIdentiry == null) + { + connectionProfile = ConnectionTestUtils.Setting.Connections.FirstOrDefault(x => x.ServerType == serverType); + } + else + { + connectionProfile = ConnectionTestUtils.Setting.GetConnentProfile(serverIdentiry.ProfileName, serverIdentiry.ServerName); + } + + if (connectionProfile != null) + { + + + string password = connectionProfile.Password; + if (string.IsNullOrEmpty(password)) + { + Credential credential = await ReadCredential(connectionProfile.formatCredentialId()); + password = credential.Password; + } + ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database, + connectionProfile.User, password); + 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 0f0866fb..005607aa 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/ConnectionTestUtils.cs @@ -29,8 +29,15 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility try { string testServerNamesFilePath = Environment.GetEnvironmentVariable("TestServerNamesFile"); - string jsonFileContent = File.ReadAllText(testServerNamesFilePath); - return Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonFileContent); + if (!string.IsNullOrEmpty(testServerNamesFilePath)) + { + string jsonFileContent = File.ReadAllText(testServerNamesFilePath); + return Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonFileContent); + } + else + { + return Enumerable.Empty(); + } } catch (Exception ex) { @@ -106,17 +113,21 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility private static string GetSettingFileContent() { string settingsFilename; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + settingsFilename = Environment.GetEnvironmentVariable("SettingsFileName"); + if (string.IsNullOrEmpty(settingsFilename)) { - settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json"; - } - else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - { - settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json"; - } - else - { - settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json"; + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json"; + } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/Library/Application Support/Code/User/settings.json"; + } + else + { + settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json"; + } } string settingsFileContents = File.ReadAllText(settingsFilename); diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/Setting.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/Setting.cs index 9349abd4..7da7eecd 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/Setting.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/Setting.cs @@ -54,6 +54,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility public string ProfileName { get; set; } + public TestServerType ServerType { get; set; } + public string formatCredentialId(string itemType = "Profile") { diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestResult.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestResult.cs new file mode 100644 index 00000000..d74d149b --- /dev/null +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestResult.cs @@ -0,0 +1,12 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility +{ + public class TestResult + { + public string ElapsedTime { get; set; } + } +} diff --git a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs index 993ed0ee..2175478e 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.TestDriver/Utility/TestTimer.cs @@ -5,6 +5,7 @@ using System; using System.Globalization; +using System.IO; namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility { @@ -13,6 +14,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility /// public class TestTimer { + private static string ResultFolder = Environment.GetEnvironmentVariable("ResultFolder"); + public TestTimer() { Start(); @@ -35,6 +38,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility 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.ToString() }); + string fileName = testName + ".json"; + string resultFilePath = string.IsNullOrEmpty(ResultFolder) ? fileName : Path.Combine(ResultFolder, fileName); + File.WriteAllText(resultFilePath, resultContent); } public double TotalMilliSeconds