diff --git a/Tests/MeloongCore.Tests.csproj b/Tests/MeloongCore.Tests.csproj index 4dae93c..0fb81f8 100644 --- a/Tests/MeloongCore.Tests.csproj +++ b/Tests/MeloongCore.Tests.csproj @@ -2,7 +2,7 @@ net48 - Library + Exe True true false @@ -23,13 +23,8 @@ - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -71,7 +66,6 @@ - @@ -83,10 +77,4 @@ - - - PreserveNewest - - - diff --git a/Tests/Utils/FileUtilsTest.cs b/Tests/Utils/FileUtilsTest.cs index 570aac1..9c5b417 100644 --- a/Tests/Utils/FileUtilsTest.cs +++ b/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(() => 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.ExtractToDirectory(GetTestFile(testFile), tempFolder)); #endregion diff --git a/Tests/Utils/PathUtilsTest.cs b/Tests/Utils/PathUtilsTest.cs index 4284041..f798100 100644 --- a/Tests/Utils/PathUtilsTest.cs +++ b/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 diff --git a/Tests/xunit.runner.json b/Tests/xunit.runner.json deleted file mode 100644 index b16d3ed..0000000 --- a/Tests/xunit.runner.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "methodDisplay": "method" -} \ No newline at end of file