From 9f6204d6e2bf323fe7dd68bc6709cdad1c2e2c6a Mon Sep 17 00:00:00 2001 From: gewuyou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 25 Apr 2026 15:30:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(core-tests):=20=E6=94=B6=E5=8F=A3=20LoggerT?= =?UTF-8?q?ests=20=E6=97=A5=E5=BF=97=E9=9B=86=E5=90=88=E6=8A=BD=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复 TestLogger.Logs 暴露 List 实现类型导致的 MA0016 warning - 保持测试桩内部写入顺序和现有测试访问方式不变 --- GFramework.Core.Tests/Logging/LoggerTests.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/GFramework.Core.Tests/Logging/LoggerTests.cs b/GFramework.Core.Tests/Logging/LoggerTests.cs index ccc207a3..3bba60a4 100644 --- a/GFramework.Core.Tests/Logging/LoggerTests.cs +++ b/GFramework.Core.Tests/Logging/LoggerTests.cs @@ -425,6 +425,8 @@ public class LoggerTests /// public sealed class TestLogger : AbstractLogger { + private readonly List _logs = new(); + /// /// 初始化TestLogger的新实例 /// @@ -435,9 +437,9 @@ public sealed class TestLogger : AbstractLogger } /// - /// 获取记录的日志条目列表 + /// 获取按写入顺序保存的日志条目只读视图 /// - public List Logs { get; } = new(); + public IReadOnlyList Logs => _logs; /// /// 将日志信息写入内部存储 @@ -447,7 +449,7 @@ public sealed class TestLogger : AbstractLogger /// 相关异常(可选) protected override void Write(LogLevel level, string message, Exception? exception) { - Logs.Add(new LogEntry(level, message, exception)); + _logs.Add(new LogEntry(level, message, exception)); } /// @@ -457,4 +459,4 @@ public sealed class TestLogger : AbstractLogger /// 日志消息 /// 相关异常(可选) public sealed record LogEntry(LogLevel Level, string Message, Exception? Exception); -} \ No newline at end of file +}