From 8c2b3b37aa61ee64b7c1f78c9b864af4cf629639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BE=99=E8=85=BE=E7=8C=AB=E8=B7=83?= <1043137532@qq.com> Date: Sat, 9 May 2026 00:39:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Shared/General/Logger.cs | 8 ++++---- Tests/MeloongCore.Tests.csproj | 6 ++++++ Tests/Utils/FileUtilsTest.cs | 16 +++++++--------- Tests/Utils/PathUtilsTest.cs | 4 ++++ Tests/xunit.runner.json | 4 ++++ 5 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 Tests/xunit.runner.json diff --git a/Shared/General/Logger.cs b/Shared/General/Logger.cs index 59a75ce..b69ca65 100644 --- a/Shared/General/Logger.cs +++ b/Shared/General/Logger.cs @@ -213,7 +213,7 @@ public class BaseLogger { /// /// 格式化日志文本。 /// - protected virtual string Format(string text, LogLevel level, string filePath, Exception? ex) { + public virtual string Format(string text, LogLevel level, string filePath, Exception? ex) { string prefix = GetLogPrefix(level, filePath); return text .ReplaceLineEndings("\n", mergeMultiple: true).Split(['\n'], StringSplitOptions.RemoveEmptyEntries) @@ -226,14 +226,14 @@ public class BaseLogger { /// /// 输出格式化后的日志文本。 /// - protected virtual void Output(string formattedMessage, LogLevel level) { + public virtual void Output(string formattedMessage, LogLevel level) { Debug.WriteLine(formattedMessage); } /// /// 在调用 Log 方法的线程执行 。 /// - protected virtual void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex) { + public virtual void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex) { } } @@ -245,7 +245,7 @@ public class BaseLogger { public class FileLogger : BaseLogger, IDisposable { /// - protected override void Output(string formattedText, LogLevel level) { + public override void Output(string formattedText, LogLevel level) { base.Output(formattedText, level); if (!writerAvailable && queue.Count >= 100) return; // 在 writer 就绪前,最多缓存 100 条日志 queue.Enqueue(formattedText); diff --git a/Tests/MeloongCore.Tests.csproj b/Tests/MeloongCore.Tests.csproj index 8f97923..4dae93c 100644 --- a/Tests/MeloongCore.Tests.csproj +++ b/Tests/MeloongCore.Tests.csproj @@ -83,4 +83,10 @@ + + + PreserveNewest + + + diff --git a/Tests/Utils/FileUtilsTest.cs b/Tests/Utils/FileUtilsTest.cs index f7342a2..570aac1 100644 --- a/Tests/Utils/FileUtilsTest.cs +++ b/Tests/Utils/FileUtilsTest.cs @@ -1,12 +1,12 @@ namespace MeloongCore.Tests; public class FileUtilsTest : TestWithFolder { - #region 压缩包 + #region 解压 [Theory] [InlineData("GB Encoding.zip")] [InlineData("UTF8 Encoding.zip")] - public void 压缩包_ReadZip(string testFile) { + public void 解压_ReadZip(string testFile) { double progress = 0; string output = Path.Combine(tempFolder, "Extracted"); FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p); @@ -19,7 +19,7 @@ public class FileUtilsTest : TestWithFolder { [Theory] [InlineData("GZ.gz", "LTCat")] - public void 压缩包_ReadGz(string testFile, string containsText) { + public void 解压_ReadGz(string testFile, string containsText) { double progress = 0; string output = Path.Combine(tempFolder, "Extracted"); FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p); @@ -30,16 +30,14 @@ public class FileUtilsTest : TestWithFolder { [Theory] [InlineData("Corrupted.zip")] [InlineData("Not zip.zip")] - public void 压缩包_ReadBad(string testFile) { - Assert.Throws(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder)); - } + 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) { - Assert.Throws(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder)); - } + 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 a2640b9..4284041 100644 --- a/Tests/Utils/PathUtilsTest.cs +++ b/Tests/Utils/PathUtilsTest.cs @@ -1,6 +1,8 @@ namespace MeloongCore.Tests; public class PathUtilsTests { + #region 路径处理 + [Theory] [InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")] [InlineData(@"C:\foo\bar.txt", @"C:\foo")] @@ -71,4 +73,6 @@ public class PathUtilsTests { public void 路径处理_GetExtension(string input, string expected) => Assert.Equal(expected, PathUtils.GetExtension(input)); + #endregion + } \ No newline at end of file diff --git a/Tests/xunit.runner.json b/Tests/xunit.runner.json new file mode 100644 index 0000000..b16d3ed --- /dev/null +++ b/Tests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", + "methodDisplay": "method" +} \ No newline at end of file