test: TestWithFolder 与 InlineData
This commit is contained in:
1 parent
19ceef907c
commit
1650e63cbd
2 files changed
+37
-77
No files matched your search
+19
-13
@@ -1,25 +1,31 @@
|
||||
namespace MeloongCore.Tests;
|
||||
public static class TestUtils {
|
||||
|
||||
/// <summary>
|
||||
/// 用于带文件测试的基类。
|
||||
/// 会在极端路径下创建测试用的临时文件夹。
|
||||
/// </summary>
|
||||
public abstract class TestWithFolder {
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个在极端路径下的测试文件夹。
|
||||
/// 测试用的临时文件夹路径。
|
||||
/// 这是一个包含特殊字符的长路径,以 \ 结尾。
|
||||
/// </summary>
|
||||
public static string GetTempFolder(string? identifier = null) {
|
||||
string folderPath = Path.Combine(
|
||||
Path.GetTempPath(), "PCL", "Tests",
|
||||
(identifier ?? "Test") + "-" + Guid.NewGuid().ToString(),
|
||||
private 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(@"\\?\" + folderPath);
|
||||
return folderPath;
|
||||
new string('X', 200), new string('X', 200)) + @"\";
|
||||
Directory.CreateDirectory(@"\\?\" + tempFolder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将指定的测试用文件输出到一个极端路径下,然后返回文件路径。
|
||||
/// 输出指定的测试用文件,返回文件路径。
|
||||
/// </summary>
|
||||
public static string GetTestFile(string directoryName, string fileName) {
|
||||
var sourceFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFiles", directoryName, fileName);
|
||||
var distPath = Path.Combine(GetTempFolder("GetTestFile"), Path.GetFileName(sourceFilePath));
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user