Merge pull request #9 from Meloong-Git/copilot/replace-xunit-with-tunit

chore: migrate test project from xunit to TUnit
This commit is contained in:
龙腾猫跃 authored and GitHub committed 2026-05-09 09:29:47 +08:00
commit b54a8f1683
4 files changed
+88 -104

No files matched your search

+2 -14
View File
@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net48</TargetFramework> <TargetFramework>net48</TargetFramework>
<OutputType>Library</OutputType> <OutputType>Exe</OutputType>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks> <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
@@ -23,13 +23,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" /> <PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.9.3" /> <PackageReference Include="TUnit" Version="1.43.38" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PolySharp" Version="1.15.0"> <PackageReference Include="PolySharp" Version="1.15.0">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -71,7 +66,6 @@
<Using Include="MeloongCore" /> <Using Include="MeloongCore" />
<Using Include="MeloongCore.Extensions" /> <Using Include="MeloongCore.Extensions" />
<Using Include="MeloongCore.Tests" /> <Using Include="MeloongCore.Tests" />
<Using Include="Xunit" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -83,10 +77,4 @@
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Update="xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>
+20 -20
View File
@@ -3,39 +3,39 @@ public class FileUtilsTest : TestWithFolder {
#region 解压 #region 解压
[Theory] [Test]
[InlineData("GB Encoding.zip")] [Arguments("GB Encoding.zip")]
[InlineData("UTF8 Encoding.zip")] [Arguments("UTF8 Encoding.zip")]
public void 解压_ReadZip(string testFile) { public async Task 解压_ReadZip(string testFile) {
double progress = 0; double progress = 0;
string output = Path.Combine(tempFolder, "Extracted"); string output = Path.Combine(tempFolder, "Extracted");
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p); FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
Assert.Equal(1, progress); await Assert.That(progress).IsEqualTo(1);
Assert.True(DirectoryUtils.Exists(Path.Combine(output, "文件夹"))); await Assert.That(DirectoryUtils.Exists(Path.Combine(output, "文件夹"))).IsTrue();
Assert.False(DirectoryUtils.Exists(Path.Combine(output, "空文件夹"))); await Assert.That(DirectoryUtils.Exists(Path.Combine(output, "空文件夹"))).IsFalse();
Assert.Contains("FabricLoader", File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "fabricloader.log")))); await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "fabricloader.log")))).Contains("FabricLoader");
Assert.Contains("测试内容", File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "文件夹", "中文文件.txt")))); await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "文件夹", "中文文件.txt")))).Contains("测试内容");
} }
[Theory] [Test]
[InlineData("GZ.gz", "LTCat")] [Arguments("GZ.gz", "LTCat")]
public void 解压_ReadGz(string testFile, string containsText) { public async Task 解压_ReadGz(string testFile, string containsText) {
double progress = 0; double progress = 0;
string output = Path.Combine(tempFolder, "Extracted"); string output = Path.Combine(tempFolder, "Extracted");
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p); FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
Assert.Equal(1, progress); await Assert.That(progress).IsEqualTo(1);
Assert.Contains(containsText, File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, PathUtils.GetFileNameWithoutExtension(testFile))))); await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, PathUtils.GetFileNameWithoutExtension(testFile))))).Contains(containsText);
} }
[Theory] [Test]
[InlineData("Corrupted.zip")] [Arguments("Corrupted.zip")]
[InlineData("Not zip.zip")] [Arguments("Not zip.zip")]
public void 解压_ReadBad(string testFile) public void 解压_ReadBad(string testFile)
=> Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder)); => Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
[Theory] [Test]
[InlineData("DotDot ZipSlip.zip")] [Arguments("DotDot ZipSlip.zip")]
[InlineData("AbsPath ZipSlip.zip")] [Arguments("AbsPath ZipSlip.zip")]
public void 解压_ZipSlip(string testFile) public void 解压_ZipSlip(string testFile)
=> Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder)); => Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
+66 -66
View File
@@ -3,75 +3,75 @@ public class PathUtilsTests {
#region 路径处理 #region 路径处理
[Theory] [Test]
[InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")] [Arguments(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
[InlineData(@"C:\foo\bar.txt", @"C:\foo")] [Arguments(@"C:\foo\bar.txt", @"C:\foo")]
[InlineData(@"\\?\C:\foo\bar", @"\\?\C:\foo")] [Arguments(@"\\?\C:\foo\bar", @"\\?\C:\foo")]
[InlineData(@"C:\foo\bar", @"C:\foo")] [Arguments(@"C:\foo\bar", @"C:\foo")]
[InlineData(@"C:\foo\bar\", @"C:\foo")] [Arguments(@"C:\foo\bar\", @"C:\foo")]
[InlineData(@"\\?\C:\foo\", @"\\?\C:")] [Arguments(@"\\?\C:\foo\", @"\\?\C:")]
[InlineData(@"C:\foo", @"C:")] [Arguments(@"C:\foo", @"C:")]
[InlineData(@"C:\foo\", @"C:")] [Arguments(@"C:\foo\", @"C:")]
[InlineData("https://foo.bar/file/long/pack.zip?arg=1", "https://foo.bar/file/long")] [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "https://foo.bar/file/long")]
[InlineData("https://foo.bar/file/", "https://foo.bar")] [Arguments("https://foo.bar/file/", "https://foo.bar")]
[InlineData("https://foo.bar/file/?arg=1", "https://foo.bar")] [Arguments("https://foo.bar/file/?arg=1", "https://foo.bar")]
[InlineData("https://foo.bar/file?arg=1", "https://foo.bar")] [Arguments("https://foo.bar/file?arg=1", "https://foo.bar")]
public void 路径处理_RemoveLastPart(string input, string expected) public async Task 路径处理_RemoveLastPart(string input, string expected)
=> Assert.Equal(expected, PathUtils.RemoveLastPart(input)); => await Assert.That(PathUtils.RemoveLastPart(input)).IsEqualTo(expected);
[Theory] [Test]
[InlineData(@"\\?\C:\foo\bar.txt", "bar.txt")] [Arguments(@"\\?\C:\foo\bar.txt", "bar.txt")]
[InlineData(@"C:\foo\bar.txt", "bar.txt")] [Arguments(@"C:\foo\bar.txt", "bar.txt")]
[InlineData(@"\\?\C:\foo\bar", "bar")] [Arguments(@"\\?\C:\foo\bar", "bar")]
[InlineData(@"C:\foo\bar", "bar")] [Arguments(@"C:\foo\bar", "bar")]
[InlineData(@"C:\foo\bar\", "bar")] [Arguments(@"C:\foo\bar\", "bar")]
[InlineData(@"\\?\C:\foo\", "foo")] [Arguments(@"\\?\C:\foo\", "foo")]
[InlineData(@"C:\foo", "foo")] [Arguments(@"C:\foo", "foo")]
[InlineData(@"C:\foo\", "foo")] [Arguments(@"C:\foo\", "foo")]
[InlineData("https://foo.bar/file/long/pack.zip?arg=1", "pack.zip")] [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "pack.zip")]
[InlineData("https://foo.bar/file/", "file")] [Arguments("https://foo.bar/file/", "file")]
[InlineData("https://foo.bar/file/?arg=1", "file")] [Arguments("https://foo.bar/file/?arg=1", "file")]
[InlineData("https://foo.bar/file?arg=1", "file")] [Arguments("https://foo.bar/file?arg=1", "file")]
public void 路径处理_GetLastPart(string input, string expected) public async Task 路径处理_GetLastPart(string input, string expected)
=> Assert.Equal(expected, PathUtils.GetLastPart(input)); => await Assert.That(PathUtils.GetLastPart(input)).IsEqualTo(expected);
[Theory] [Test]
[InlineData(@"\\?\C:\foo\bar.txt", "bar")] [Arguments(@"\\?\C:\foo\bar.txt", "bar")]
[InlineData(@"C:\foo\bar.2.txt", "bar.2")] [Arguments(@"C:\foo\bar.2.txt", "bar.2")]
[InlineData(@"\\?\C:\foo\bar", "bar")] [Arguments(@"\\?\C:\foo\bar", "bar")]
[InlineData(@"C:\foo\bar", "bar")] [Arguments(@"C:\foo\bar", "bar")]
[InlineData(@"C:\foo.bar\how\", "how")] [Arguments(@"C:\foo.bar\how\", "how")]
[InlineData(@"\\?\C:\foo\", "foo")] [Arguments(@"\\?\C:\foo\", "foo")]
[InlineData(@"C:\foo", "foo")] [Arguments(@"C:\foo", "foo")]
[InlineData(@"C:\foo\", "foo")] [Arguments(@"C:\foo\", "foo")]
[InlineData("create.jar.disabled", "create.jar")] [Arguments("create.jar.disabled", "create.jar")]
[InlineData("create.jar", "create")] [Arguments("create.jar", "create")]
[InlineData("create", "create")] [Arguments("create", "create")]
[InlineData("https://foo.bar/file/page.xaml.vb?arg=1", "page.xaml")] [Arguments("https://foo.bar/file/page.xaml.vb?arg=1", "page.xaml")]
[InlineData("https://foo.bar/file/long/pack.zip?arg=1", "pack")] [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "pack")]
[InlineData("https://foo.bar/some.how/file/", "file")] [Arguments("https://foo.bar/some.how/file/", "file")]
[InlineData("https://foo.bar/file/?arg=1", "file")] [Arguments("https://foo.bar/file/?arg=1", "file")]
[InlineData("https://foo.bar/file?arg=1", "file")] [Arguments("https://foo.bar/file?arg=1", "file")]
public void 路径处理_GetFileNameWithoutExtension(string input, string expected) public async Task 路径处理_GetFileNameWithoutExtension(string input, string expected)
=> Assert.Equal(expected, PathUtils.GetFileNameWithoutExtension(input)); => await Assert.That(PathUtils.GetFileNameWithoutExtension(input)).IsEqualTo(expected);
[Theory] [Test]
[InlineData(@"\\?\C:\FOO\BAR.TXT", "txt")] [Arguments(@"\\?\C:\FOO\BAR.TXT", "txt")]
[InlineData(@"C:\foo\bar.txt", "txt")] [Arguments(@"C:\foo\bar.txt", "txt")]
[InlineData(@"\\?\C:\foo\bar", "")] [Arguments(@"\\?\C:\foo\bar", "")]
[InlineData(@"C:\foo\bar", "")] [Arguments(@"C:\foo\bar", "")]
[InlineData(@"C:\foo\bar\", "")] [Arguments(@"C:\foo\bar\", "")]
[InlineData(@"\\?\C:\foo\", "")] [Arguments(@"\\?\C:\foo\", "")]
[InlineData(@"C:\foo", "")] [Arguments(@"C:\foo", "")]
[InlineData(@"C:\foo\", "")] [Arguments(@"C:\foo\", "")]
[InlineData("create.jar.diSAbled", "disabled")] [Arguments("create.jar.diSAbled", "disabled")]
[InlineData("https://foo.bar/file/page.xaml.vb?arg=1", "vb")] [Arguments("https://foo.bar/file/page.xaml.vb?arg=1", "vb")]
[InlineData("https://foo.bar/file/long/pack.ZIP?arg=1", "zip")] [Arguments("https://foo.bar/file/long/pack.ZIP?arg=1", "zip")]
[InlineData("https://foo.bar/file/", "")] [Arguments("https://foo.bar/file/", "")]
[InlineData("https://foo.bar/file/?arg=1", "")] [Arguments("https://foo.bar/file/?arg=1", "")]
[InlineData("https://foo.bar/file?arg=1", "")] [Arguments("https://foo.bar/file?arg=1", "")]
public void 路径处理_GetExtension(string input, string expected) public async Task 路径处理_GetExtension(string input, string expected)
=> Assert.Equal(expected, PathUtils.GetExtension(input)); => await Assert.That(PathUtils.GetExtension(input)).IsEqualTo(expected);
#endregion #endregion
-4
View File
@@ -1,4 +0,0 @@
{
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
"methodDisplay": "method"
}