From 13229f1c910653c91dd69545b11497c2d0cb1116 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Thu, 26 Feb 2026 19:52:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(logging):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=BF=BD=E5=8A=A0=E5=99=A8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E8=B5=84=E6=BA=90=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构 Constructor_ShouldCreateDirectoryIfNotExists 测试方法名称为更描述性的格式 - 使用 using 语句块确保 FileAppender 资源得到正确释放 - 改进测试代码结构以提高可读性和资源清理可靠性 --- GFramework.Core.Tests/logging/FileAppenderTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/GFramework.Core.Tests/logging/FileAppenderTests.cs b/GFramework.Core.Tests/logging/FileAppenderTests.cs index d1a7641..9906d77 100644 --- a/GFramework.Core.Tests/logging/FileAppenderTests.cs +++ b/GFramework.Core.Tests/logging/FileAppenderTests.cs @@ -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 {