mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 21:34:28 +08:00
refactor(logging): 优化文件追加器测试中的资源管理
- 重构 Constructor_ShouldCreateDirectoryIfNotExists 测试方法名称为更描述性的格式 - 使用 using 语句块确保 FileAppender 资源得到正确释放 - 改进测试代码结构以提高可读性和资源清理可靠性
This commit is contained in:
parent
e94e4890cd
commit
13229f1c91
@ -48,17 +48,18 @@ public class FileAppenderTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Constructor_ShouldCreateDirectoryIfNotExists()
|
public void Constructor_WhenDirectoryDoesNotExist_ShouldCreateIt()
|
||||||
{
|
{
|
||||||
var dirPath = Path.Combine(Path.GetTempPath(), $"test_dir_{Guid.NewGuid()}");
|
var dirPath = Path.Combine(Path.GetTempPath(), $"test_dir_{Guid.NewGuid()}");
|
||||||
var filePath = Path.Combine(dirPath, "test.log");
|
var filePath = Path.Combine(dirPath, "test.log");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using var appender = new FileAppender(filePath);
|
using (new FileAppender(filePath))
|
||||||
|
{
|
||||||
Assert.That(Directory.Exists(dirPath), Is.True);
|
Assert.That(Directory.Exists(dirPath), Is.True);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
if (Directory.Exists(dirPath))
|
if (Directory.Exists(dirPath))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user