2025-01-03 16:21:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using Autofac;
|
|
|
|
|
|
using Microsoft.ApplicationInsights;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-02-20 00:23:13 +01:00
|
|
|
|
using PlanTempus.Core.Configurations;
|
|
|
|
|
|
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
|
|
|
|
|
using PlanTempus.Core.ModuleRegistry;
|
|
|
|
|
|
namespace PlanTempus.Tests
|
2025-01-03 16:21:03 +00:00
|
|
|
|
{
|
2025-02-22 20:14:56 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Act as base class for tests. Avoids duplication of test setup code
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public abstract partial class TestFixture
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly string _configurationFilePath;
|
|
|
|
|
|
|
|
|
|
|
|
protected IContainer Container { get; private set; }
|
|
|
|
|
|
protected ContainerBuilder ContainerBuilder { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IConfigurationRoot Configuration()
|
|
|
|
|
|
{
|
|
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
|
|
|
|
.AddJsonFile($"{_configurationFilePath}appconfiguration.dev.json")
|
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
return configuration;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected TestFixture() : this(null) { }
|
|
|
|
|
|
public TestFixture(string configurationFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (configurationFilePath is not null)
|
|
|
|
|
|
_configurationFilePath = configurationFilePath?.TrimEnd('/') + "/";
|
|
|
|
|
|
|
|
|
|
|
|
CreateContainerBuilder();
|
|
|
|
|
|
Container = ContainerBuilder.Build();
|
|
|
|
|
|
}
|
|
|
|
|
|
protected virtual void CreateContainerBuilder()
|
|
|
|
|
|
{
|
|
|
|
|
|
IConfigurationRoot configuration = Configuration();
|
|
|
|
|
|
|
|
|
|
|
|
//var logger = new LoggerConfiguration()
|
|
|
|
|
|
// .MinimumLevel.Verbose()
|
|
|
|
|
|
// .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
|
|
|
|
|
|
// .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Error)
|
|
|
|
|
|
// .WriteTo.Seq("http://localhost:5341", apiKey: "Gt8hS9ClGNfOCAdswDlW")
|
|
|
|
|
|
// .WriteTo.ApplicationInsights(configuration.Get<string>("ApplicationInsights:ConnectionString"),
|
|
|
|
|
|
// TelemetryConverter.Traces)
|
|
|
|
|
|
// .Enrich.FromLogContext()
|
|
|
|
|
|
// .Enrich.WithMachineName()
|
|
|
|
|
|
// .CreateLogger();
|
|
|
|
|
|
|
|
|
|
|
|
var builder = new ContainerBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterGeneric(typeof(Logger<>))
|
|
|
|
|
|
.As(typeof(ILogger<>))
|
|
|
|
|
|
.SingleInstance();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
|
|
|
|
|
{
|
|
|
|
|
|
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
builder.RegisterModule(new TelemetryModule
|
|
|
|
|
|
{
|
|
|
|
|
|
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
|
|
|
|
|
});
|
|
|
|
|
|
builder.RegisterModule(new SeqLoggingModule
|
|
|
|
|
|
{
|
|
|
|
|
|
SeqConfiguration = configuration.GetSection("SeqConfiguration").ToObject<Core.Logging.SeqConfiguration>()
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ContainerBuilder = builder;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestCleanup]
|
|
|
|
|
|
public void CleanUp()
|
|
|
|
|
|
{
|
|
|
|
|
|
Trace.Flush();
|
|
|
|
|
|
var telemetryClient = Container.Resolve<TelemetryClient>();
|
|
|
|
|
|
telemetryClient.Flush();
|
|
|
|
|
|
|
|
|
|
|
|
if (Container != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Container.Dispose();
|
|
|
|
|
|
Container = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2025-01-03 16:21:03 +00:00
|
|
|
|
}
|