namespace MeloongCore.Tests; /// /// 用于带文件测试的基类。 /// 会在极端路径下创建测试用的临时文件夹。 /// public abstract class TestWithFolder { /// /// 测试用的临时文件夹路径。 /// 这是一个包含特殊字符的长路径,不以 \\?\ 开头,以 \ 结尾。 /// public readonly string tempFolder; public TestWithFolder() { tempFolder = Path.Combine( Path.GetTempPath(), "PCL", "Tests", $"{GetType().Name}-{Guid.NewGuid()}", "文件夹 Dir_!@#$%^&()_+={}[];',_", new string('X', 200), new string('X', 200)) + @"\"; Directory.CreateDirectory(@"\\?\" + tempFolder); } /// /// 输出指定的测试用文件,返回文件路径。 /// public string GetTestFile(string fileName) { var sourceFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", GetType().Name.Replace("Test", ""), fileName); var distPath = Path.Combine(tempFolder, Path.GetFileName(sourceFilePath)); File.Copy(sourceFilePath, @"\\?\" + distPath); return distPath; } }