2025迁移版本,多项规则修改

This commit is contained in:
2024-12-10 14:03:09 +08:00
parent dc239c776e
commit 0e28d639c1
34 changed files with 1075 additions and 564 deletions

View File

@@ -0,0 +1,38 @@
using System.Text.Json;
using Microsoft.Extensions.Logging;
using Serilog;
using TestProject1.XUnit.Logging;
using Xunit.Abstractions;
namespace TestProject1.XUnit;
public class TestBase
{
private readonly LoggerFactory _loggerFactory;
protected readonly ITestOutputHelper Output;
private readonly JsonSerializerOptions _jsonSerializerOptions =
new(JsonSerializerDefaults.Web) { WriteIndented = true };
public TestBase(ITestOutputHelper output)
{
Output = output;
Console.SetOut(new XUnitConsoleWriter(output));
_loggerFactory = new LoggerFactory([new XunitLoggerProvider(Output)]);
}
protected void Write(object obj)
{
Output.WriteLine(obj.ToString());
}
protected void WriteJson<T>(T obj)
{
Console.WriteLine(JsonSerializer.Serialize(obj, _jsonSerializerOptions));
}
protected ILogger<T> CreateXUnitLogger<T>()
{
return _loggerFactory.CreateLogger<T>();
}
}