BootstrapAdmin/UnitTest/TestHelper.cs

42 lines
1.3 KiB
C#

using System;
using System.IO;
namespace UnitTest
{
public static class TestHelper
{
/// <summary>
/// 获得当前工程解决方案目录
/// </summary>
/// <returns></returns>
public static string RetrieveSolutionPath()
{
var dirSeparator = Path.DirectorySeparatorChar;
var paths = AppContext.BaseDirectory.SpanSplit($"{dirSeparator}.vs{dirSeparator}");
return paths.Count > 1 ? paths[0] : Path.Combine(AppContext.BaseDirectory, $"..{dirSeparator}..{dirSeparator}..{dirSeparator}..{dirSeparator}");
}
/// <summary>
///
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
public static string RetrievePath(string folder)
{
var soluFolder = RetrieveSolutionPath();
return Path.Combine(soluFolder, folder);
}
/// <summary>
///
/// </summary>
public static void CopyLicense()
{
var licFile = RetrievePath($"UnitTest{Path.DirectorySeparatorChar}License{Path.DirectorySeparatorChar}Longbow.lic");
var targetFile = Path.Combine(AppContext.BaseDirectory, "Longbow.lic");
if (!File.Exists(targetFile)) File.Copy(licFile, targetFile, true);
}
}
}