using Autofac; using Serilog; using Serilog.Core; using Xunit.Abstractions; namespace Nitride.Tests { /// /// Common initialization logic for Nitride-based tests including setting /// up containers, logging, and Serilog. /// 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() .SingleInstance(); builder.RegisterModule(); this.ConfigureContainer(builder); this.Container = builder.Build(); } /// /// Contains the Autofac container for this test. /// protected IContainer Container { get; } /// /// Gets the logger used to report messages about the test. /// protected Logger Logger { get; } /// /// Configures the Autofac container for this test instance. /// /// protected virtual void ConfigureContainer(ContainerBuilder builder) { } } }