Просмотр исходного кода

chore: replace xunit with TUnit in test project

Agent-Logs-Url: https://github.com/Meloong-Git/MeloongCore/sessions/ec3e9ba1-2e5f-4e12-9954-204846b6e793

Co-authored-by: LTCatt <[email protected]>
copilot-swe-agent[bot] 5 месяцев назад
Родитель
Сommit
b44fee289b
4 измененных файлов с 90 добавлено и 106 удалено
  1. 2 14
      Tests/MeloongCore.Tests.csproj
  2. 22 22
      Tests/Utils/FileUtilsTest.cs
  3. 66 66
      Tests/Utils/PathUtilsTest.cs
  4. 0 4
      Tests/xunit.runner.json

+ 2 - 14
Tests/MeloongCore.Tests.csproj

@@ -2,7 +2,7 @@
 
 	<PropertyGroup>
 		<TargetFramework>net48</TargetFramework>
-		<OutputType>Library</OutputType>
+		<OutputType>Exe</OutputType>
 		<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
 		<Deterministic>true</Deterministic>
 		<IsPackable>false</IsPackable>
@@ -23,13 +23,8 @@
 	</ItemGroup>
 
 	<ItemGroup>
-		<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
 		<PackageReference Include="System.IO.Compression" Version="4.3.0" />
-		<PackageReference Include="xunit" Version="2.9.3" />
-		<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
-			<PrivateAssets>all</PrivateAssets>
-			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
-		</PackageReference>
+		<PackageReference Include="TUnit" Version="1.43.38" />
 		<PackageReference Include="PolySharp" Version="1.15.0">
 			<PrivateAssets>all</PrivateAssets>
 			<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -71,7 +66,6 @@
 		<Using Include="MeloongCore" />
 		<Using Include="MeloongCore.Extensions" />
 		<Using Include="MeloongCore.Tests" />
-		<Using Include="Xunit" />
 	</ItemGroup>
 
 	<ItemGroup>
@@ -83,10 +77,4 @@
 		<Reference Include="PresentationFramework" />
 	</ItemGroup>
 
-	<ItemGroup>
-	  <None Update="xunit.runner.json">
-	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
-	  </None>
-	</ItemGroup>
-
 </Project>

+ 22 - 22
Tests/Utils/FileUtilsTest.cs

@@ -3,40 +3,40 @@ public class FileUtilsTest : TestWithFolder {
 
     #region 解压
 
-    [Theory]
-    [InlineData("GB Encoding.zip")]
-    [InlineData("UTF8 Encoding.zip")]
-    public void 解压_ReadZip(string testFile) {
+    [Test]
+    [Arguments("GB Encoding.zip")]
+    [Arguments("UTF8 Encoding.zip")]
+    public async Task 解压_ReadZip(string testFile) {
         double progress = 0;
         string output = Path.Combine(tempFolder, "Extracted");
         FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
-        Assert.Equal(1, progress);
-        Assert.True(DirectoryUtils.Exists(Path.Combine(output, "文件夹")));
-        Assert.False(DirectoryUtils.Exists(Path.Combine(output, "空文件夹")));
-        Assert.Contains("FabricLoader", File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "fabricloader.log"))));
-        Assert.Contains("测试内容", File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "文件夹", "中文文件.txt"))));
+        await Assert.That(progress).IsEqualTo(1);
+        await Assert.That(DirectoryUtils.Exists(Path.Combine(output, "文件夹"))).IsTrue();
+        await Assert.That(DirectoryUtils.Exists(Path.Combine(output, "空文件夹"))).IsFalse();
+        await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "fabricloader.log")))).Contains("FabricLoader");
+        await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, "文件夹", "中文文件.txt")))).Contains("测试内容");
     }
 
-    [Theory]
-    [InlineData("GZ.gz", "LTCat")]
-    public void 解压_ReadGz(string testFile, string containsText) {
+    [Test]
+    [Arguments("GZ.gz", "LTCat")]
+    public async Task 解压_ReadGz(string testFile, string containsText) {
         double progress = 0;
         string output = Path.Combine(tempFolder, "Extracted");
         FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
-        Assert.Equal(1, progress);
-        Assert.Contains(containsText, File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, PathUtils.GetFileNameWithoutExtension(testFile)))));
+        await Assert.That(progress).IsEqualTo(1);
+        await Assert.That(File.ReadAllText(PathUtils.WithLongPath(Path.Combine(output, PathUtils.GetFileNameWithoutExtension(testFile))))).Contains(containsText);
     }
 
-    [Theory]
-    [InlineData("Corrupted.zip")]
-    [InlineData("Not zip.zip")]
-    public void 解压_ReadBad(string testFile) 
+    [Test]
+    [Arguments("Corrupted.zip")]
+    [Arguments("Not zip.zip")]
+    public void 解压_ReadBad(string testFile)
         => Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
 
-    [Theory]
-    [InlineData("DotDot ZipSlip.zip")]
-    [InlineData("AbsPath ZipSlip.zip")]
-    public void 解压_ZipSlip(string testFile) 
+    [Test]
+    [Arguments("DotDot ZipSlip.zip")]
+    [Arguments("AbsPath ZipSlip.zip")]
+    public void 解压_ZipSlip(string testFile)
         => Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
 
     #endregion

+ 66 - 66
Tests/Utils/PathUtilsTest.cs

@@ -3,75 +3,75 @@ public class PathUtilsTests {
 
     #region 路径处理
 
-    [Theory]
-    [InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
-    [InlineData(@"C:\foo\bar.txt", @"C:\foo")]
-    [InlineData(@"\\?\C:\foo\bar", @"\\?\C:\foo")]
-    [InlineData(@"C:\foo\bar", @"C:\foo")]
-    [InlineData(@"C:\foo\bar\", @"C:\foo")]
-    [InlineData(@"\\?\C:\foo\", @"\\?\C:")]
-    [InlineData(@"C:\foo", @"C:")]
-    [InlineData(@"C:\foo\", @"C:")]
-    [InlineData("https://foo.bar/file/long/pack.zip?arg=1", "https://foo.bar/file/long")]
-    [InlineData("https://foo.bar/file/", "https://foo.bar")]
-    [InlineData("https://foo.bar/file/?arg=1", "https://foo.bar")]
-    [InlineData("https://foo.bar/file?arg=1", "https://foo.bar")]
-    public void 路径处理_RemoveLastPart(string input, string expected) 
-        => Assert.Equal(expected, PathUtils.RemoveLastPart(input));
+    [Test]
+    [Arguments(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
+    [Arguments(@"C:\foo\bar.txt", @"C:\foo")]
+    [Arguments(@"\\?\C:\foo\bar", @"\\?\C:\foo")]
+    [Arguments(@"C:\foo\bar", @"C:\foo")]
+    [Arguments(@"C:\foo\bar\", @"C:\foo")]
+    [Arguments(@"\\?\C:\foo\", @"\\?\C:")]
+    [Arguments(@"C:\foo", @"C:")]
+    [Arguments(@"C:\foo\", @"C:")]
+    [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "https://foo.bar/file/long")]
+    [Arguments("https://foo.bar/file/", "https://foo.bar")]
+    [Arguments("https://foo.bar/file/?arg=1", "https://foo.bar")]
+    [Arguments("https://foo.bar/file?arg=1", "https://foo.bar")]
+    public async Task 路径处理_RemoveLastPart(string input, string expected)
+        => await Assert.That(PathUtils.RemoveLastPart(input)).IsEqualTo(expected);
 
-    [Theory]
-    [InlineData(@"\\?\C:\foo\bar.txt", "bar.txt")]
-    [InlineData(@"C:\foo\bar.txt", "bar.txt")]
-    [InlineData(@"\\?\C:\foo\bar", "bar")]
-    [InlineData(@"C:\foo\bar", "bar")]
-    [InlineData(@"C:\foo\bar\", "bar")]
-    [InlineData(@"\\?\C:\foo\", "foo")]
-    [InlineData(@"C:\foo", "foo")]
-    [InlineData(@"C:\foo\", "foo")]
-    [InlineData("https://foo.bar/file/long/pack.zip?arg=1", "pack.zip")]
-    [InlineData("https://foo.bar/file/", "file")]
-    [InlineData("https://foo.bar/file/?arg=1", "file")]
-    [InlineData("https://foo.bar/file?arg=1", "file")]
-    public void 路径处理_GetLastPart(string input, string expected)
-        => Assert.Equal(expected, PathUtils.GetLastPart(input));
+    [Test]
+    [Arguments(@"\\?\C:\foo\bar.txt", "bar.txt")]
+    [Arguments(@"C:\foo\bar.txt", "bar.txt")]
+    [Arguments(@"\\?\C:\foo\bar", "bar")]
+    [Arguments(@"C:\foo\bar", "bar")]
+    [Arguments(@"C:\foo\bar\", "bar")]
+    [Arguments(@"\\?\C:\foo\", "foo")]
+    [Arguments(@"C:\foo", "foo")]
+    [Arguments(@"C:\foo\", "foo")]
+    [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "pack.zip")]
+    [Arguments("https://foo.bar/file/", "file")]
+    [Arguments("https://foo.bar/file/?arg=1", "file")]
+    [Arguments("https://foo.bar/file?arg=1", "file")]
+    public async Task 路径处理_GetLastPart(string input, string expected)
+        => await Assert.That(PathUtils.GetLastPart(input)).IsEqualTo(expected);
 
-    [Theory]
-    [InlineData(@"\\?\C:\foo\bar.txt", "bar")]
-    [InlineData(@"C:\foo\bar.2.txt", "bar.2")]
-    [InlineData(@"\\?\C:\foo\bar", "bar")]
-    [InlineData(@"C:\foo\bar", "bar")]
-    [InlineData(@"C:\foo.bar\how\", "how")]
-    [InlineData(@"\\?\C:\foo\", "foo")]
-    [InlineData(@"C:\foo", "foo")]
-    [InlineData(@"C:\foo\", "foo")]
-    [InlineData("create.jar.disabled", "create.jar")]
-    [InlineData("create.jar", "create")]
-    [InlineData("create", "create")]
-    [InlineData("https://foo.bar/file/page.xaml.vb?arg=1", "page.xaml")]
-    [InlineData("https://foo.bar/file/long/pack.zip?arg=1", "pack")]
-    [InlineData("https://foo.bar/some.how/file/", "file")]
-    [InlineData("https://foo.bar/file/?arg=1", "file")]
-    [InlineData("https://foo.bar/file?arg=1", "file")]
-    public void 路径处理_GetFileNameWithoutExtension(string input, string expected)
-        => Assert.Equal(expected, PathUtils.GetFileNameWithoutExtension(input));
+    [Test]
+    [Arguments(@"\\?\C:\foo\bar.txt", "bar")]
+    [Arguments(@"C:\foo\bar.2.txt", "bar.2")]
+    [Arguments(@"\\?\C:\foo\bar", "bar")]
+    [Arguments(@"C:\foo\bar", "bar")]
+    [Arguments(@"C:\foo.bar\how\", "how")]
+    [Arguments(@"\\?\C:\foo\", "foo")]
+    [Arguments(@"C:\foo", "foo")]
+    [Arguments(@"C:\foo\", "foo")]
+    [Arguments("create.jar.disabled", "create.jar")]
+    [Arguments("create.jar", "create")]
+    [Arguments("create", "create")]
+    [Arguments("https://foo.bar/file/page.xaml.vb?arg=1", "page.xaml")]
+    [Arguments("https://foo.bar/file/long/pack.zip?arg=1", "pack")]
+    [Arguments("https://foo.bar/some.how/file/", "file")]
+    [Arguments("https://foo.bar/file/?arg=1", "file")]
+    [Arguments("https://foo.bar/file?arg=1", "file")]
+    public async Task 路径处理_GetFileNameWithoutExtension(string input, string expected)
+        => await Assert.That(PathUtils.GetFileNameWithoutExtension(input)).IsEqualTo(expected);
 
-    [Theory]
-    [InlineData(@"\\?\C:\FOO\BAR.TXT", "txt")]
-    [InlineData(@"C:\foo\bar.txt", "txt")]
-    [InlineData(@"\\?\C:\foo\bar", "")]
-    [InlineData(@"C:\foo\bar", "")]
-    [InlineData(@"C:\foo\bar\", "")]
-    [InlineData(@"\\?\C:\foo\", "")]
-    [InlineData(@"C:\foo", "")]
-    [InlineData(@"C:\foo\", "")]
-    [InlineData("create.jar.diSAbled", "disabled")]
-    [InlineData("https://foo.bar/file/page.xaml.vb?arg=1", "vb")]
-    [InlineData("https://foo.bar/file/long/pack.ZIP?arg=1", "zip")]
-    [InlineData("https://foo.bar/file/", "")]
-    [InlineData("https://foo.bar/file/?arg=1", "")]
-    [InlineData("https://foo.bar/file?arg=1", "")]
-    public void 路径处理_GetExtension(string input, string expected)
-        => Assert.Equal(expected, PathUtils.GetExtension(input));
+    [Test]
+    [Arguments(@"\\?\C:\FOO\BAR.TXT", "txt")]
+    [Arguments(@"C:\foo\bar.txt", "txt")]
+    [Arguments(@"\\?\C:\foo\bar", "")]
+    [Arguments(@"C:\foo\bar", "")]
+    [Arguments(@"C:\foo\bar\", "")]
+    [Arguments(@"\\?\C:\foo\", "")]
+    [Arguments(@"C:\foo", "")]
+    [Arguments(@"C:\foo\", "")]
+    [Arguments("create.jar.diSAbled", "disabled")]
+    [Arguments("https://foo.bar/file/page.xaml.vb?arg=1", "vb")]
+    [Arguments("https://foo.bar/file/long/pack.ZIP?arg=1", "zip")]
+    [Arguments("https://foo.bar/file/", "")]
+    [Arguments("https://foo.bar/file/?arg=1", "")]
+    [Arguments("https://foo.bar/file?arg=1", "")]
+    public async Task 路径处理_GetExtension(string input, string expected)
+        => await Assert.That(PathUtils.GetExtension(input)).IsEqualTo(expected);
 
     #endregion
 

+ 0 - 4
Tests/xunit.runner.json

@@ -1,4 +0,0 @@
-{
-  "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
-  "methodDisplay": "method"
-}