2025迁移版本,多项规则修改
This commit is contained in:
38
MesETL.Test/XUnit/TestBase.cs
Normal file
38
MesETL.Test/XUnit/TestBase.cs
Normal 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>();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user