mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(logging): 优化文件追加器测试中的资源管理
- 重构 Constructor_ShouldCreateDirectoryIfNotExists 测试方法名称为更描述性的格式 - 使用 using 语句块确保 FileAppender 资源得到正确释放 - 改进测试代码结构以提高可读性和资源清理可靠性
This commit is contained in:
parent
e94e4890cd
commit
13229f1c91
@ -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
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user