This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/tests/Nitride.Tests/NitrideTestsBase.cs

64 lines
1.7 KiB
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using Autofac;
using Serilog;
using Serilog.Core;
using Xunit.Abstractions;
namespace Nitride.Tests
{
/// <summary>
/// Common initialization logic for Nitride-based tests including setting
/// up containers, logging, and Serilog.
/// </summary>
public abstract class NitrideTestsBase
{
private readonly ITestOutputHelper output;
public NitrideTestsBase(ITestOutputHelper output)
{
this.output = output;
// Set up logging.
const string Template =
"[{Level:u3}] "
+ "({SourceContext}) {Message}"
+ "{NewLine}{Exception}";
this.Logger = new LoggerConfiguration()
.WriteTo.TestOutput(
output,
outputTemplate: Template)
.CreateLogger();
// Set up Autofac.
var builder = new ContainerBuilder();
builder.RegisterInstance(this.Logger)
.As<ILogger>()
.SingleInstance();
builder.RegisterModule<NitrideModule>();
this.ConfigureContainer(builder);
this.Container = builder.Build();
}
/// <summary>
/// Contains the Autofac container for this test.
/// </summary>
protected IContainer Container { get; }
/// <summary>
/// Gets the logger used to report messages about the test.
/// </summary>
protected Logger Logger { get; }
/// <summary>
/// Configures the Autofac container for this test instance.
/// </summary>
/// <param name="builder"></param>
protected virtual void ConfigureContainer(ContainerBuilder builder)
{
}
}
}