From 737d0b5037fd249be288b2cc895355cd65183721 Mon Sep 17 00:00:00 2001 From: gewuyou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 25 Apr 2026 10:03:26 +0800 Subject: [PATCH] =?UTF-8?q?test(core-tests):=20=E6=98=BE=E5=BC=8F=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E6=97=A5=E5=BF=97=E6=B5=8B=E8=AF=95=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E6=AF=94=E8=BE=83=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 LogEntryTests 与格式化器测试中的字符串字典补充 StringComparer.Ordinal - 保持日志相关测试断言与行为路径不变 --- .../Logging/DefaultLogFormatterTests.cs | 6 +++--- .../Logging/JsonLogFormatterTests.cs | 8 ++++---- GFramework.Core.Tests/Logging/LogEntryTests.cs | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/GFramework.Core.Tests/Logging/DefaultLogFormatterTests.cs b/GFramework.Core.Tests/Logging/DefaultLogFormatterTests.cs index 7d363e98..9d607520 100644 --- a/GFramework.Core.Tests/Logging/DefaultLogFormatterTests.cs +++ b/GFramework.Core.Tests/Logging/DefaultLogFormatterTests.cs @@ -48,7 +48,7 @@ public class DefaultLogFormatterTests [Test] public void Format_WithProperties_ShouldIncludeProperties() { - var properties = new Dictionary + var properties = new Dictionary(StringComparer.Ordinal) { ["UserId"] = 12345, ["UserName"] = "TestUser" @@ -66,7 +66,7 @@ public class DefaultLogFormatterTests [Test] public void Format_WithNullProperty_ShouldHandleNull() { - var properties = new Dictionary + var properties = new Dictionary(StringComparer.Ordinal) { ["Key1"] = null }; @@ -114,4 +114,4 @@ public class DefaultLogFormatterTests Assert.That(result, Does.Contain(message)); } -} \ No newline at end of file +} diff --git a/GFramework.Core.Tests/Logging/JsonLogFormatterTests.cs b/GFramework.Core.Tests/Logging/JsonLogFormatterTests.cs index 3808770f..138b7dc3 100644 --- a/GFramework.Core.Tests/Logging/JsonLogFormatterTests.cs +++ b/GFramework.Core.Tests/Logging/JsonLogFormatterTests.cs @@ -54,7 +54,7 @@ public class JsonLogFormatterTests [Test] public void Format_WithProperties_ShouldIncludePropertiesObject() { - var properties = new Dictionary + var properties = new Dictionary(StringComparer.Ordinal) { ["UserId"] = 12345, ["UserName"] = "TestUser", @@ -93,7 +93,7 @@ public class JsonLogFormatterTests [Test] public void Format_WithNullProperty_ShouldHandleNull() { - var properties = new Dictionary + var properties = new Dictionary(StringComparer.Ordinal) { ["Key1"] = null, ["Key2"] = "value" @@ -170,7 +170,7 @@ public class JsonLogFormatterTests [Test] public void Format_WithComplexProperties_ShouldSerializeCorrectly() { - var properties = new Dictionary + var properties = new Dictionary(StringComparer.Ordinal) { ["Number"] = 123, ["String"] = "test", @@ -184,4 +184,4 @@ public class JsonLogFormatterTests Assert.That(() => JsonDocument.Parse(result), Throws.Nothing); } -} \ No newline at end of file +} diff --git a/GFramework.Core.Tests/Logging/LogEntryTests.cs b/GFramework.Core.Tests/Logging/LogEntryTests.cs index 76d8a0eb..bd7f2e9b 100644 --- a/GFramework.Core.Tests/Logging/LogEntryTests.cs +++ b/GFramework.Core.Tests/Logging/LogEntryTests.cs @@ -13,7 +13,7 @@ public class LogEntryTests public void Constructor_WithAllParameters_ShouldCreateEntry() { var timestamp = DateTime.UtcNow; - var properties = new Dictionary { ["Key1"] = "Value1" }; + var properties = new Dictionary(StringComparer.Ordinal) { ["Key1"] = "Value1" }; var exception = new InvalidOperationException("Test"); var entry = new LogEntry(timestamp, LogLevel.Info, "TestLogger", "Test message", exception, properties); @@ -63,7 +63,7 @@ public class LogEntryTests public void GetAllProperties_WithProperties_ShouldReturnOnlyProperties() { LogContext.Clear(); - var properties = new Dictionary { ["PropKey"] = "PropValue" }; + var properties = new Dictionary(StringComparer.Ordinal) { ["PropKey"] = "PropValue" }; var entry = new LogEntry(DateTime.UtcNow, LogLevel.Info, "TestLogger", "Test message", null, properties); var allProps = entry.GetAllProperties(); @@ -78,7 +78,7 @@ public class LogEntryTests LogContext.Clear(); using (LogContext.Push("ContextKey", "ContextValue")) { - var properties = new Dictionary { ["PropKey"] = "PropValue" }; + var properties = new Dictionary(StringComparer.Ordinal) { ["PropKey"] = "PropValue" }; var entry = new LogEntry(DateTime.UtcNow, LogLevel.Info, "TestLogger", "Test message", null, properties); var allProps = entry.GetAllProperties(); @@ -97,7 +97,7 @@ public class LogEntryTests LogContext.Clear(); using (LogContext.Push("Key1", "ContextValue")) { - var properties = new Dictionary { ["Key1"] = "PropValue" }; + var properties = new Dictionary(StringComparer.Ordinal) { ["Key1"] = "PropValue" }; var entry = new LogEntry(DateTime.UtcNow, LogLevel.Info, "TestLogger", "Test message", null, properties); var allProps = entry.GetAllProperties(); @@ -124,7 +124,7 @@ public class LogEntryTests public void RecordEquality_WithSameValues_ShouldBeEqual() { var timestamp = DateTime.UtcNow; - var properties = new Dictionary { ["Key1"] = "Value1" }; + var properties = new Dictionary(StringComparer.Ordinal) { ["Key1"] = "Value1" }; var entry1 = new LogEntry(timestamp, LogLevel.Info, "TestLogger", "Test message", null, properties); var entry2 = new LogEntry(timestamp, LogLevel.Info, "TestLogger", "Test message", null, properties); @@ -142,4 +142,4 @@ public class LogEntryTests Assert.That(entry1, Is.Not.EqualTo(entry2)); } -} \ No newline at end of file +}