Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.Test.Common/RunEnvironmentInfo.cs
Aditya Bist 25c5c27a6e Fix batch parser test (#239)
* fixed batch parser test

* fix batch parser test

* fix batch parser test

* fixed baseline tests for parser and fixed trace output logic

* Update RunEnvironmentInfo.cs

* checking error logs on AppVeyor

* checking error logs on app veyor

* changed file reading encoding

* adding logs to app veyor build

* changed encoding of baseline files

* added error logs for app veyor

* changed error logs for app veyor

* changed how file stream works in batch parser tests

* changed baseline and testscript encodings

* cleaned code for necessary batch parser tests
2017-02-24 15:49:45 -08:00

113 lines
4.5 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
{
/// <summary>
/// Contains environment information needed when running tests.
/// </summary>
public class RunEnvironmentInfo
{
private static string cachedTestFolderPath;
private static string cachedTraceFolderPath;
public static bool IsLabMode()
{
string bvtLabRoot = Environment.GetEnvironmentVariable(Constants.BVTLocalRoot);
if (string.IsNullOrEmpty(bvtLabRoot))
{
return false;
}
return true;
}
/// <summary>
/// Location of all test data (baselines, etc).
/// </summary>
/// <returns>The full path to the test data directory</returns>
public static string GetTestDataLocation()
{
string testFolderPath;
string testPath = Path.Combine("test", "Microsoft.SqlTools.ServiceLayer.Test.Common", "TestData");
string projectPath = Environment.GetEnvironmentVariable(Constants.ProjectPath);
if (projectPath != null)
{
testFolderPath = Path.Combine(projectPath, testPath);
}
else
{
if (cachedTestFolderPath != null)
{
testFolderPath = cachedTestFolderPath;
}
else
{
// We are running tests locally, which means we expect to be running inside the bin\debug\netcoreapp directory
// Test Files should be found at the root of the project so go back the necessary number of directories for this
// to be found. We are manually specifying the testFolderPath here for clarity on where to expect this
string assemblyDir = Path.GetDirectoryName(typeof(Scripts).GetTypeInfo().Assembly.Location);
string defaultPath = Path.Combine(assemblyDir, GoUpNDirectories(4));
testFolderPath = Path.Combine(defaultPath, "Microsoft.SqlTools.ServiceLayer.Test.Common", "TestData");
cachedTestFolderPath = testFolderPath;
}
}
return testFolderPath;
}
/// <summary>
/// Location of all trace data (expected output)
/// </summary>
/// <returns>The full path to the trace data directory</returns>
public static string GetTraceOutputLocation()
{
string traceFolderPath;
string testPath = @"test\Microsoft.SqlTools.ServiceLayer.Test.Common\Trace";
string projectPath = Environment.GetEnvironmentVariable(Constants.ProjectPath);
if (projectPath != null)
{
traceFolderPath = Path.Combine(projectPath, testPath);
}
else
{
if (cachedTraceFolderPath != null)
{
traceFolderPath = cachedTraceFolderPath;
}
else
{
// We are running tests locally, which means we expect to be running inside the bin\debug\netcoreapp directory
// Test Files should be found at the root of the project so go back the necessary number of directories for this
// to be found. We are manually specifying the testFolderPath here for clarity on where to expect this
string assemblyDir = Path.GetDirectoryName(typeof(Scripts).GetTypeInfo().Assembly.Location);
string defaultPath = Path.Combine(assemblyDir, GoUpNDirectories(4));
traceFolderPath = Path.Combine(defaultPath, "Microsoft.SqlTools.ServiceLayer.Test.Common", "TestData");
cachedTraceFolderPath = traceFolderPath;
}
}
return traceFolderPath;
}
private static string GoUpNDirectories(int n)
{
string up = ".." + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "\\" : "/");
return string.Concat(Enumerable.Repeat(up, n));
}
}
}