mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-11 04:04:29 +08:00
test(core-tests): 规范字符串比较断言写法
- 优化 ContextAwareServiceExtensionsTests 中的字符串相等断言,显式使用 Ordinal 比较 - 优化 RollingFileAppenderTests 中的 StartsWith、EndsWith、排序比较与文件名判等写法,补充 Ordinal 比较并保持测试语义不变
This commit is contained in:
parent
f67b2cedb2
commit
6188876570
@ -68,7 +68,7 @@ public class RollingFileAppenderTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否生成了多个文件
|
// 检查是否生成了多个文件
|
||||||
var files = Directory.GetFiles(_testDir, "*.log").OrderBy(f => f).ToArray();
|
var files = Directory.GetFiles(_testDir, "*.log").OrderBy(f => f, System.StringComparer.Ordinal).ToArray();
|
||||||
Assert.That(files.Length, Is.GreaterThan(1));
|
Assert.That(files.Length, Is.GreaterThan(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,13 +108,21 @@ public class RollingFileAppenderTests
|
|||||||
appender.Flush();
|
appender.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
var files = Directory.GetFiles(_testDir, "*.log").Select(Path.GetFileName).OrderBy(f => f).ToArray();
|
var files = Directory.GetFiles(_testDir, "*.log")
|
||||||
|
.Select(static path => Path.GetFileName(path) ?? string.Empty)
|
||||||
|
.OrderBy(f => f, System.StringComparer.Ordinal)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
// 应该有 app.log, app.1.log, app.2.log 等
|
// 应该有 app.log, app.1.log, app.2.log 等
|
||||||
Assert.That(files, Does.Contain("app.log"));
|
Assert.That(files, Does.Contain("app.log"));
|
||||||
if (files.Length > 1)
|
if (files.Length > 1)
|
||||||
{
|
{
|
||||||
Assert.That(files.Any(f => f.StartsWith("app.") && f.EndsWith(".log") && f != "app.log"), Is.True);
|
Assert.That(
|
||||||
|
files.Any(f =>
|
||||||
|
f.StartsWith("app.", System.StringComparison.Ordinal) &&
|
||||||
|
f.EndsWith(".log", System.StringComparison.Ordinal) &&
|
||||||
|
!string.Equals(f, "app.log", System.StringComparison.Ordinal)),
|
||||||
|
Is.True);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,4 +171,4 @@ public class RollingFileAppenderTests
|
|||||||
var content = File.ReadAllText(_testFilePath);
|
var content = File.ReadAllText(_testFilePath);
|
||||||
Assert.That(content, Does.Contain("Test message"));
|
Assert.That(content, Does.Contain("Test message"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,8 +181,8 @@ public class ContextAwareServiceExtensionsTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.That(results, Has.Count.GreaterThanOrEqualTo(2));
|
Assert.That(results, Has.Count.GreaterThanOrEqualTo(2));
|
||||||
Assert.That(results.Any(s => s is TestSystem ts && ts.Name == "System1"), Is.True);
|
Assert.That(results.Any(s => s is TestSystem ts && string.Equals(ts.Name, "System1", System.StringComparison.Ordinal)), Is.True);
|
||||||
Assert.That(results.Any(s => s is TestSystem ts && ts.Name == "System2"), Is.True);
|
Assert.That(results.Any(s => s is TestSystem ts && string.Equals(ts.Name, "System2", System.StringComparison.Ordinal)), Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -200,8 +200,8 @@ public class ContextAwareServiceExtensionsTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.That(results, Has.Count.EqualTo(2));
|
Assert.That(results, Has.Count.EqualTo(2));
|
||||||
Assert.That(results.Any(m => m.Name == "Model1"), Is.True);
|
Assert.That(results.Any(m => string.Equals(m.Name, "Model1", System.StringComparison.Ordinal)), Is.True);
|
||||||
Assert.That(results.Any(m => m.Name == "Model2"), Is.True);
|
Assert.That(results.Any(m => string.Equals(m.Name, "Model2", System.StringComparison.Ordinal)), Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -219,8 +219,8 @@ public class ContextAwareServiceExtensionsTests
|
|||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.That(results, Has.Count.EqualTo(2));
|
Assert.That(results, Has.Count.EqualTo(2));
|
||||||
Assert.That(results.Any(u => u.Name == "Utility1"), Is.True);
|
Assert.That(results.Any(u => string.Equals(u.Name, "Utility1", System.StringComparison.Ordinal)), Is.True);
|
||||||
Assert.That(results.Any(u => u.Name == "Utility2"), Is.True);
|
Assert.That(results.Any(u => string.Equals(u.Name, "Utility2", System.StringComparison.Ordinal)), Is.True);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -304,4 +304,4 @@ public class ContextAwareServiceExtensionsTests
|
|||||||
private class TestContextAware : ContextAwareBase
|
private class TestContextAware : ContextAwareBase
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user