FileSqlServerSync/Server/ServerTest/FilesSeed.cs
zerlei 1809dbebf5 chore: 完成了文件操作,现在可以对旧文件夹执行更新策略,并添加了单元测试
1. 写逻辑复杂的程序,单元测试必不可少,重构和修改更有信心
2. 单元测试每个测试函数应该是独立的,不相互依赖的,也应该是简单的,否则出现问题不好排查,它叫单元测试
3. 运行测试和debug的时候不要害怕😰😰😰😰😰🙃🙃🙃🙃🙃❤️❤️❤️❤️❤️,它帮你找到了错误,完全没有否定你的意思·····
2024-10-12 21:58:37 +08:00

197 lines
7.9 KiB
C#

using System.Text;
using Common;
namespace ServerTest;
public class FilesSeed : IDisposable
{
public FilesSeed()
{
Console.WriteLine("FilesSeed Construct");
// string TestPath = Path.Combine(Directory.GetCurrentDirectory(), "../../..");
DateTime NewTime = DateTime.Now.AddSeconds(-99);
DateTime OldTime = NewTime.AddSeconds(-20);
NewDir = new Dir(
TestPath + "/NewDir",
[
new Dir($"{TestPath}/NewDir/0"),
new Dir(
$"{TestPath}/NewDir/1",
[new Common.File($"{TestPath}/NewDir/1/1.txt", NewTime)]
),
new Dir(
$"{TestPath}/NewDir/2",
[
new Common.File($"{TestPath}/NewDir/2/2.txt", NewTime),
new Dir(
$"{TestPath}/NewDir/2/2_1",
[
new Common.File($"{TestPath}/NewDir/2/2_1/1.txt", NewTime),
new Common.File($"{TestPath}/NewDir/2/2_1/2.txt", NewTime),
]
),
new Dir(
$"{TestPath}/NewDir/2/2_2",
[
new Common.File($"{TestPath}/NewDir/2/2_2/1.txt", NewTime),
new Common.File($"{TestPath}/NewDir/2/2_2/2.txt", NewTime),
new Dir(
$"{TestPath}/NewDir/2/2_2/2_3",
[
new Common.File(
$"{TestPath}/NewDir/2/2_2/2_3/1.txt",
NewTime
),
]
),
]
)
]
),
]
);
DiffDir = new Dir(
$"{TestPath}/OldDir",
[
new Dir(
$"{TestPath}/OldDir/1",
[new Common.File($"{TestPath}/OldDir/1/2_D.txt", NewTime, NextOpType.Del),]
),
new Dir(
$"{TestPath}/OldDir/2",
[
// 将要添加
new Common.File($"{TestPath}/OldDir/2/2.txt", NewTime, NextOpType.Add),
new Dir(
$"{TestPath}/OldDir/2/2_1",
[
new Common.File(
$"{TestPath}/OldDir/2/2_1/2.txt",
NewTime,
NextOpType.Modify
),
]
),
new Dir(
$"{TestPath}/OldDir/2/2_2_M",
[
new Common.File(
$"{TestPath}/OldDir/2/2_2_M/1.txt",
OldTime,
NextOpType.Del
),
new Common.File(
$"{TestPath}/OldDir/2/2_2_M/2.txt",
OldTime,
NextOpType.Del
),
new Dir(
$"{TestPath}/OldDir/2/2_2_M/2_3",
[
new Common.File(
$"{TestPath}/OldDir/2/2_2_M/2_3/1.txt",
OldTime,
NextOpType.Del
),
],
NextOpType.Del
),
],
NextOpType.Del
),
new Dir(
$"{TestPath}/OldDir/2/2_2",
[
new Common.File(
$"{TestPath}/OldDir/2/2_2/1.txt",
NewTime,
NextOpType.Add
),
new Common.File(
$"{TestPath}/OldDir/2/2_2/2.txt",
NewTime,
NextOpType.Add
),
new Dir(
$"{TestPath}/OldDir/2/2_2/2_3",
[
new Common.File(
$"{TestPath}/OldDir/2/2_2/2_3/1.txt",
NewTime,
NextOpType.Add
),
],
NextOpType.Add
),
],
NextOpType.Add
)
]
),
]
);
OldDir = new Dir(
$"{TestPath}/OldDir",
[
new Dir($"{TestPath}/OldDir/0"),
new Dir(
$"{TestPath}/OldDir/1",
[
//不做修改
new Common.File($"{TestPath}/OldDir/1/1.txt", NewTime),
//将要删除
new Common.File($"{TestPath}/OldDir/1/2_D.txt", NewTime),
]
),
new Dir(
$"{TestPath}/OldDir/2",
[
new Dir(
$"{TestPath}/OldDir/2/2_1",
[
new Common.File($"{TestPath}/OldDir/2/2_1/1.txt", NewTime),
new Common.File($"{TestPath}/OldDir/2/2_1/2.txt", OldTime),
]
),
new Dir(
$"{TestPath}/OldDir/2/2_2_M",
[
new Common.File($"{TestPath}/OldDir/2/2_2_M/1.txt", OldTime),
new Common.File($"{TestPath}/OldDir/2/2_2_M/2.txt", OldTime),
new Dir(
$"{TestPath}/OldDir/2/2_2_M/2_3",
[
new Common.File(
$"{TestPath}/OldDir/2/2_2_M/2_3/1.txt",
OldTime
),
]
),
]
)
]
),
]
);
fileDirOp = new SimpleFileDirOpForTest();
}
private readonly string TestPath = Path.Combine(Directory.GetCurrentDirectory(), "../../..");
public Dir NewDir;
public Dir OldDir;
public Dir DiffDir;
public FileDirOp fileDirOp;
public void Dispose()
{
Directory.Delete($"{TestPath}/OldDir", true);
Directory.Delete($"{TestPath}/NewDir", true);
Console.WriteLine("FilesSeed Dispose");
GC.SuppressFinalize(this);
}
// ~FilesSeed()
// {
// Console.WriteLine("FilesSeed ~");
// }
}