refactor(logging): 优化文件追加器测试中的资源管理

- 重构 Constructor_ShouldCreateDirectoryIfNotExists 测试方法名称为更描述性的格式
- 使用 using 语句块确保 FileAppender 资源得到正确释放
- 改进测试代码结构以提高可读性和资源清理可靠性
This commit is contained in:
GeWuYou 2026-02-26 19:52:30 +08:00 committed by gewuyou
parent e94e4890cd
commit 13229f1c91

View File

@ -48,16 +48,17 @@ public class FileAppenderTests
}
[Test]
public void Constructor_ShouldCreateDirectoryIfNotExists()
public void Constructor_WhenDirectoryDoesNotExist_ShouldCreateIt()
{
var dirPath = Path.Combine(Path.GetTempPath(), $"test_dir_{Guid.NewGuid()}");
var filePath = Path.Combine(dirPath, "test.log");
try
{
using var appender = new FileAppender(filePath);
Assert.That(Directory.Exists(dirPath), Is.True);
using (new FileAppender(filePath))
{
Assert.That(Directory.Exists(dirPath), Is.True);
}
}
finally
{