测试微调
This commit is contained in:
1 parent
f760befa26
commit
8c2b3b37aa
5 files changed
+25
-13
No files matched your search
@@ -213,7 +213,7 @@ public class BaseLogger {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 格式化日志文本。
|
/// 格式化日志文本。
|
||||||
/// </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);
|
string prefix = GetLogPrefix(level, filePath);
|
||||||
return text
|
return text
|
||||||
.ReplaceLineEndings("\n", mergeMultiple: true).Split(['\n'], StringSplitOptions.RemoveEmptyEntries)
|
.ReplaceLineEndings("\n", mergeMultiple: true).Split(['\n'], StringSplitOptions.RemoveEmptyEntries)
|
||||||
@@ -226,14 +226,14 @@ public class BaseLogger {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 输出格式化后的日志文本。
|
/// 输出格式化后的日志文本。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void Output(string formattedMessage, LogLevel level) {
|
public virtual void Output(string formattedMessage, LogLevel level) {
|
||||||
Debug.WriteLine(formattedMessage);
|
Debug.WriteLine(formattedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在调用 Log 方法的线程执行 <see cref="LogBehavior"/>。
|
/// 在调用 Log 方法的线程执行 <see cref="LogBehavior"/>。
|
||||||
/// </summary>
|
/// </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 {
|
public class FileLogger : BaseLogger, IDisposable {
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
protected override void Output(string formattedText, LogLevel level) {
|
public override void Output(string formattedText, LogLevel level) {
|
||||||
base.Output(formattedText, level);
|
base.Output(formattedText, level);
|
||||||
if (!writerAvailable && queue.Count >= 100) return; // 在 writer 就绪前,最多缓存 100 条日志
|
if (!writerAvailable && queue.Count >= 100) return; // 在 writer 就绪前,最多缓存 100 条日志
|
||||||
queue.Enqueue(formattedText);
|
queue.Enqueue(formattedText);
|
||||||
|
|||||||
@@ -83,4 +83,10 @@
|
|||||||
<Reference Include="PresentationFramework" />
|
<Reference Include="PresentationFramework" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="xunit.runner.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
namespace MeloongCore.Tests;
|
namespace MeloongCore.Tests;
|
||||||
public class FileUtilsTest : TestWithFolder {
|
public class FileUtilsTest : TestWithFolder {
|
||||||
|
|
||||||
#region 压缩包
|
#region 解压
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("GB Encoding.zip")]
|
[InlineData("GB Encoding.zip")]
|
||||||
[InlineData("UTF8 Encoding.zip")]
|
[InlineData("UTF8 Encoding.zip")]
|
||||||
public void 压缩包_ReadZip(string testFile) {
|
public void 解压_ReadZip(string testFile) {
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
string output = Path.Combine(tempFolder, "Extracted");
|
string output = Path.Combine(tempFolder, "Extracted");
|
||||||
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
|
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
|
||||||
@@ -19,7 +19,7 @@ public class FileUtilsTest : TestWithFolder {
|
|||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("GZ.gz", "LTCat")]
|
[InlineData("GZ.gz", "LTCat")]
|
||||||
public void 压缩包_ReadGz(string testFile, string containsText) {
|
public void 解压_ReadGz(string testFile, string containsText) {
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
string output = Path.Combine(tempFolder, "Extracted");
|
string output = Path.Combine(tempFolder, "Extracted");
|
||||||
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
|
FileUtils.ExtractToDirectory(GetTestFile(testFile), output, p => progress = p);
|
||||||
@@ -30,16 +30,14 @@ public class FileUtilsTest : TestWithFolder {
|
|||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("Corrupted.zip")]
|
[InlineData("Corrupted.zip")]
|
||||||
[InlineData("Not zip.zip")]
|
[InlineData("Not zip.zip")]
|
||||||
public void 压缩包_ReadBad(string testFile) {
|
public void 解压_ReadBad(string testFile)
|
||||||
Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
|
=> Assert.Throws<InvalidDataException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
|
||||||
}
|
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData("DotDot ZipSlip.zip")]
|
[InlineData("DotDot ZipSlip.zip")]
|
||||||
[InlineData("AbsPath ZipSlip.zip")]
|
[InlineData("AbsPath ZipSlip.zip")]
|
||||||
public void 压缩包_ZipSlip(string testFile) {
|
public void 解压_ZipSlip(string testFile)
|
||||||
Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
|
=> Assert.Throws<FileUtils.ZipSlipException>(() => FileUtils.ExtractToDirectory(GetTestFile(testFile), tempFolder));
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
namespace MeloongCore.Tests;
|
namespace MeloongCore.Tests;
|
||||||
public class PathUtilsTests {
|
public class PathUtilsTests {
|
||||||
|
|
||||||
|
#region 路径处理
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
|
[InlineData(@"\\?\C:\foo\bar.txt", @"\\?\C:\foo")]
|
||||||
[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)
|
public void 路径处理_GetExtension(string input, string expected)
|
||||||
=> Assert.Equal(expected, PathUtils.GetExtension(input));
|
=> Assert.Equal(expected, PathUtils.GetExtension(input));
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://xunit.net/schema/current/xunit.runner.schema.json",
|
||||||
|
"methodDisplay": "method"
|
||||||
|
}
|
||||||
Reference in new issue
Block a user