using System; using System.IO; namespace UnitTest { public static class TestHelper { /// /// 获得当前工程解决方案目录 /// /// 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}"); } /// /// /// /// /// public static string RetrievePath(string folder) { var soluFolder = RetrieveSolutionPath(); return Path.Combine(soluFolder, folder); } /// /// /// 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); } } }