test: 极端路径构建
This commit is contained in:
1 parent
f8b2c0bbff
commit
19ceef907c
2 files changed
+108
-112
No files matched your search
+18
-2
@@ -2,10 +2,26 @@
|
||||
public static class TestUtils {
|
||||
|
||||
/// <summary>
|
||||
/// 获取测试用文件的路径。
|
||||
/// 获取一个在极端路径下的测试文件夹。
|
||||
/// </summary>
|
||||
public static string GetTempFolder(string? identifier = null) {
|
||||
string folderPath = Path.Combine(
|
||||
Path.GetTempPath(), "PCL", "Tests",
|
||||
(identifier ?? "Test") + "-" + Guid.NewGuid().ToString(),
|
||||
"文件夹 Dir_!@#$%^&()_+={}[];',_",
|
||||
new string('X', 200), new string('X', 200));
|
||||
Directory.CreateDirectory(@"\\?\" + folderPath);
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将指定的测试用文件输出到一个极端路径下,然后返回文件路径。
|
||||
/// </summary>
|
||||
public static string GetTestFile(string directoryName, string fileName) {
|
||||
return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", directoryName, fileName);
|
||||
var sourceFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", directoryName, fileName);
|
||||
var distPath = Path.Combine(GetTempFolder("GetTestFile"), Path.GetFileName(sourceFilePath));
|
||||
File.Copy(sourceFilePath, @"\\?\" + distPath);
|
||||
return distPath;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user