84 lines
No EOL
2.5 KiB
C#
84 lines
No EOL
2.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using Autofac;
|
|
using Core.Configurations;
|
|
using Core.ModuleRegistry;
|
|
using Microsoft.ApplicationInsights;
|
|
using Microsoft.Extensions.Logging;
|
|
using Core.Configurations.JsonConfigProvider;
|
|
namespace Tests
|
|
{
|
|
/// <summary>
|
|
/// Act as base class for tests. Avoids duplication of test setup code
|
|
/// </summary>
|
|
[TestClass]
|
|
public abstract partial class TestFixture
|
|
{
|
|
protected IContainer Container { get; private set; }
|
|
protected ContainerBuilder ContainerBuilder { get; private set; }
|
|
|
|
public virtual IConfigurationRoot Configuration()
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddJsonFile("appconfiguration.dev.json")
|
|
.Build();
|
|
|
|
return configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Should not be overriden. Rather override PreArrangeAll to setup data needed for a test class.
|
|
/// Override PrebuildContainer with a method that does nothing to prevent early build of IOC container
|
|
/// </summary>
|
|
[TestInitialize]
|
|
public void Setup()
|
|
{
|
|
CreateContainerBuilder();
|
|
Container = ContainerBuilder.Build();
|
|
Insight.Database.Providers.PostgreSQL.PostgreSQLInsightDbProvider.RegisterProvider();
|
|
}
|
|
|
|
|
|
protected virtual void CreateContainerBuilder()
|
|
{
|
|
IConfigurationRoot configuration = Configuration();
|
|
|
|
var builder = new ContainerBuilder();
|
|
builder.RegisterInstance(new LoggerFactory())
|
|
.As<ILoggerFactory>();
|
|
|
|
builder.RegisterGeneric(typeof(Logger<>))
|
|
.As(typeof(ILogger<>))
|
|
.SingleInstance();
|
|
|
|
builder.RegisterModule(new Core.ModuleRegistry.DbPostgreSqlModule
|
|
{
|
|
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
|
});
|
|
|
|
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
|
{
|
|
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
|
});
|
|
|
|
|
|
|
|
ContainerBuilder = builder;
|
|
}
|
|
|
|
[TestCleanup]
|
|
public void CleanUp()
|
|
{
|
|
Trace.Flush();
|
|
var telemetryClient = Container.Resolve<TelemetryClient>();
|
|
telemetryClient.Flush();
|
|
|
|
if (Container != null)
|
|
{
|
|
Container.Dispose();
|
|
Container = null;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |