Browse Source

测试微调

龙腾猫跃 5 months ago
parent
commit
8c2b3b37aa

+ 4 - 4
Shared/General/Logger.cs

@@ -213,7 +213,7 @@ public class BaseLogger {
     /// <summary>
     /// 格式化日志文本。
     /// </summary>
-    protected virtual string Format(string text, LogLevel level, string filePath, Exception? ex) {
+    public virtual string Format(string text, LogLevel level, string filePath, Exception? ex) {
         string prefix = GetLogPrefix(level, filePath);
         return text
             .ReplaceLineEndings("\n", mergeMultiple: true).Split(['\n'], StringSplitOptions.RemoveEmptyEntries)
@@ -226,14 +226,14 @@ public class BaseLogger {
     /// <summary>
     /// 输出格式化后的日志文本。
     /// </summary>
-    protected virtual void Output(string formattedMessage, LogLevel level) {
+    public virtual void Output(string formattedMessage, LogLevel level) {
         Debug.WriteLine(formattedMessage);
     }
 
     /// <summary>
     /// 在调用 Log 方法的线程执行 <see cref="LogBehavior"/>。
     /// </summary>
-    protected virtual void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex) {
+    public virtual void HandleBehavior(string? rawMessage, string formattedMessage, LogBehavior behavior, Exception? ex) {
     }
 
 }
@@ -245,7 +245,7 @@ public class BaseLogger {
 public class FileLogger : BaseLogger, IDisposable {
 
     /// <inheritdoc/>
-    protected override void Output(string formattedText, LogLevel level) {
+    public override void Output(string formattedText, LogLevel level) {
         base.Output(formattedText, level);
         if (!writerAvailable && queue.Count >= 100) return; // 在 writer 就绪前,最多缓存 100 条日志
         queue.Enqueue(formattedText);

+ 6 - 0
Tests/MeloongCore.Tests.csproj

@@ -83,4 +83,10 @@
 		<Reference Include="PresentationFramework" />
 	</ItemGroup>
 
+	<ItemGroup>
+	  <None Update="xunit.runner.json">
+	    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+	  </None>
+	</ItemGroup>
+
 </Project>

+ 7 - 9
Tests/Utils/FileUtilsTest.cs

@@ -1,12 +1,12 @@
 namespace MeloongCore.Tests;
 public class FileUtilsTest : TestWithFolder {
 
-    #region 压缩包
+    #region 解压
 
     [Theory]
     [InlineData("GB Encoding.zip")]
     [InlineData("UTF8 Encoding.zip")]
-    public void 压缩包_ReadZip(string testFile) {
+    public void 解压_ReadZip(string testFile) {
         double progress = 0;
         string output = Path.Combine(tempFolder, "Extracted");
         FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
@@ -19,7 +19,7 @@ public class FileUtilsTest : TestWithFolder {
 
     [Theory]
     [InlineData("GZ.gz", "LTCat")]
-    public void 压缩包_ReadGz(string testFile, string containsText) {
+    public void 解压_ReadGz(string testFile, string containsText) {
         double progress = 0;
         string output = Path.Combine(tempFolder, "Extracted");
         FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
@@ -30,16 +30,14 @@ public class FileUtilsTest : TestWithFolder {
     [Theory]
     [InlineData("Corrupted.zip")]
     [InlineData("Not zip.zip")]
-    public void 压缩包_ReadBad(string testFile) {
-        Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
-    }
+    public void 解压_ReadBad(string testFile) 
+        => Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
 
     [Theory]
     [InlineData("DotDot ZipSlip.zip")]
     [InlineData("AbsPath ZipSlip.zip")]
-    public void 压缩包_ZipSlip(string testFile) {
-        Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
-    }
+    public void 解压_ZipSlip(string testFile) 
+        => Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
 
     #endregion
 

+ 4 - 0
Tests/Utils/PathUtilsTest.cs

@@ -1,6 +1,8 @@
 namespace MeloongCore.Tests;
 public class PathUtilsTests {
 
+    #region 路径处理
+
     [Theory]
     [InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
     [InlineData(@"C:\foo\bar.txt", @"C:\foo")]
@@ -71,4 +73,6 @@ public class PathUtilsTests {
     public void 路径处理_GetExtension(string input, string expected)
         => Assert.Equal(expected, PathUtils.GetExtension(input));
 
+    #endregion
+
 }

+ 4 - 0
Tests/xunit.runner.json

@@ -0,0 +1,4 @@
+{
+  "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
+  "methodDisplay": "method"
+}