64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
|
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)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
}
|