test(core-tests): 显式指定日志测试字符串比较器

- 为 LogEntryTests 与格式化器测试中的字符串字典补充 StringComparer.Ordinal
- 保持日志相关测试断言与行为路径不变
This commit is contained in:
gewuyou 2026-04-25 10:03:26 +08:00
parent 6188876570
commit 737d0b5037
3 changed files with 13 additions and 13 deletions

View File

@ -48,7 +48,7 @@ public class DefaultLogFormatterTests
[Test]
public void Format_WithProperties_ShouldIncludeProperties()
{
var properties = new Dictionary<string, object?>
var properties = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["UserId"] = 12345,
["UserName"] = "TestUser"
@ -66,7 +66,7 @@ public class DefaultLogFormatterTests
[Test]
public void Format_WithNullProperty_ShouldHandleNull()
{
var properties = new Dictionary<string, object?>
var properties = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["Key1"] = null
};
@ -114,4 +114,4 @@ public class DefaultLogFormatterTests
Assert.That(result, Does.Contain(message));
}
}
}

View File

@ -54,7 +54,7 @@ public class JsonLogFormatterTests
[Test]
public void Format_WithProperties_ShouldIncludePropertiesObject()
{
var properties = new Dictionary<string, object?>
var properties = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["UserId"] = 12345,
["UserName"] = "TestUser",
@ -93,7 +93,7 @@ public class JsonLogFormatterTests
[Test]
public void Format_WithNullProperty_ShouldHandleNull()
{
var properties = new Dictionary<string, object?>
var properties = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["Key1"] = null,
["Key2"] = "value"
@ -170,7 +170,7 @@ public class JsonLogFormatterTests
[Test]
public void Format_WithComplexProperties_ShouldSerializeCorrectly()
{
var properties = new Dictionary<string, object?>
var properties = new Dictionary<string, object?>(StringComparer.Ordinal)
{
["Number"] = 123,
["String"] = "test",
@ -184,4 +184,4 @@ public class JsonLogFormatterTests
Assert.That(() => JsonDocument.Parse(result), Throws.Nothing);
}
}
}

View File

@ -13,7 +13,7 @@ public class LogEntryTests
public void Constructor_WithAllParameters_ShouldCreateEntry()
{
var timestamp = DateTime.UtcNow;
var properties = new Dictionary<string, object?> { ["Key1"] = "Value1" };
var properties = new Dictionary<string, object?>(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<string, object?> { ["PropKey"] = "PropValue" };
var properties = new Dictionary<string, object?>(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<string, object?> { ["PropKey"] = "PropValue" };
var properties = new Dictionary<string, object?>(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<string, object?> { ["Key1"] = "PropValue" };
var properties = new Dictionary<string, object?>(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<string, object?> { ["Key1"] = "Value1" };
var properties = new Dictionary<string, object?>(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));
}
}
}