If the test name file cannot be found just use the settings.json

This commit is contained in:
Leila Lali
2016-11-09 16:12:11 -08:00
parent 92420e734f
commit 18bf76caed
6 changed files with 81 additions and 18 deletions

View File

@@ -18,9 +18,18 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
{ {
public class PerformanceTests : TestBase 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 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] [Fact]
public async Task HoverTestOnPrem() public async Task HoverTestOnPrem()
{ {
@@ -556,6 +565,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
TestTimer timer = new TestTimer(); TestTimer timer = new TestTimer();
T result = await testToRun(); T result = await testToRun();
timer.EndAndPrint(testName); timer.EndAndPrint(testName);
return result; return result;
} }
} }

View File

@@ -183,13 +183,33 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Tests
/// </summary> /// </summary>
protected async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType) protected async Task<ConnectParams> GetDatabaseConnectionAsync(TestServerType serverType)
{ {
ConnectionProfile connectionProfile = null;
TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType); TestServerIdentity serverIdentiry = ConnectionTestUtils.TestServers.FirstOrDefault(x => x.ServerType == serverType);
var connectionProfile = ConnectionTestUtils.Setting.GetConnentProfile(serverIdentiry.ProfileName, serverIdentiry.ServerName); 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()); Credential credential = await ReadCredential(connectionProfile.formatCredentialId());
password = credential.Password;
}
ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database, ConnectParams conenctParam = ConnectionTestUtils.CreateConnectParams(connectionProfile.ServerName, connectionProfile.Database,
connectionProfile.User, credential.Password); connectionProfile.User, password);
return conenctParam; return conenctParam;
} }
return null;
}
/// <summary> /// <summary>
/// Request a list of completion items for a position in a block of text /// Request a list of completion items for a position in a block of text

View File

@@ -29,9 +29,16 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
try try
{ {
string testServerNamesFilePath = Environment.GetEnvironmentVariable("TestServerNamesFile"); string testServerNamesFilePath = Environment.GetEnvironmentVariable("TestServerNamesFile");
if (!string.IsNullOrEmpty(testServerNamesFilePath))
{
string jsonFileContent = File.ReadAllText(testServerNamesFilePath); string jsonFileContent = File.ReadAllText(testServerNamesFilePath);
return Newtonsoft.Json.JsonConvert.DeserializeObject<IList<TestServerIdentity>>(jsonFileContent); return Newtonsoft.Json.JsonConvert.DeserializeObject<IList<TestServerIdentity>>(jsonFileContent);
} }
else
{
return Enumerable.Empty<TestServerIdentity>();
}
}
catch (Exception ex) catch (Exception ex)
{ {
return null; return null;
@@ -106,6 +113,9 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
private static string GetSettingFileContent() private static string GetSettingFileContent()
{ {
string settingsFilename; string settingsFilename;
settingsFilename = Environment.GetEnvironmentVariable("SettingsFileName");
if (string.IsNullOrEmpty(settingsFilename))
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json"; settingsFilename = Environment.GetEnvironmentVariable("APPDATA") + @"\Code\User\settings.json";
@@ -118,6 +128,7 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{ {
settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json"; settingsFilename = Environment.GetEnvironmentVariable("HOME") + @"/.config/Code/User/settings.json";
} }
}
string settingsFileContents = File.ReadAllText(settingsFilename); string settingsFileContents = File.ReadAllText(settingsFilename);
return settingsFileContents; return settingsFileContents;

View File

@@ -54,6 +54,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
public string ProfileName { get; set; } public string ProfileName { get; set; }
public TestServerType ServerType { get; set; }
public string formatCredentialId(string itemType = "Profile") public string formatCredentialId(string itemType = "Profile")
{ {

View File

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

View File

@@ -5,6 +5,7 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.IO;
namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
{ {
@@ -13,6 +14,8 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
/// </summary> /// </summary>
public class TestTimer public class TestTimer
{ {
private static string ResultFolder = Environment.GetEnvironmentVariable("ResultFolder");
public TestTimer() public TestTimer()
{ {
Start(); Start();
@@ -35,6 +38,10 @@ namespace Microsoft.SqlTools.ServiceLayer.TestDriver.Utility
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds)); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test Name: {0} Run time in milliSeconds: {1}", testName, TotalMilliSeconds));
Console.ForegroundColor = currentColor; 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 public double TotalMilliSeconds