wip
This commit is contained in:
parent
0f1a345216
commit
e73f428c49
6 changed files with 96 additions and 144 deletions
|
|
@ -8,92 +8,92 @@ 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
|
||||
{
|
||||
private readonly string _configurationFilePath;
|
||||
/// <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; }
|
||||
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();
|
||||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile($"{_configurationFilePath}appconfiguration.dev.json")
|
||||
.Build();
|
||||
|
||||
return configuration;
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
protected TestFixture()
|
||||
{
|
||||
CreateContainerBuilder();
|
||||
Container = ContainerBuilder.Build();
|
||||
}
|
||||
public TestFixture(string configurationFilePath) : this()
|
||||
{
|
||||
_configurationFilePath = configurationFilePath;
|
||||
}
|
||||
protected virtual void CreateContainerBuilder()
|
||||
{
|
||||
IConfigurationRoot configuration = Configuration();
|
||||
protected TestFixture() : this(null) { }
|
||||
public TestFixture(string configurationFilePath)
|
||||
{
|
||||
if (configurationFilePath is not null)
|
||||
_configurationFilePath = configurationFilePath?.TrimEnd('/') + "/";
|
||||
|
||||
//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();
|
||||
CreateContainerBuilder();
|
||||
Container = ContainerBuilder.Build();
|
||||
}
|
||||
protected virtual void CreateContainerBuilder()
|
||||
{
|
||||
IConfigurationRoot configuration = Configuration();
|
||||
|
||||
//Log.Logger = logger;
|
||||
//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();
|
||||
|
||||
//Log.Logger.Verbose("Is thos work");
|
||||
var builder = new ContainerBuilder();
|
||||
//Log.Logger = logger;
|
||||
|
||||
//Log.Logger.Verbose("Is thos work");
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
|
||||
//builder.Register(c => new SerilogLoggerFactory(logger))
|
||||
// .As<ILoggerFactory>()
|
||||
// .SingleInstance();
|
||||
//builder.Register(c => new SerilogLoggerFactory(logger))
|
||||
// .As<ILoggerFactory>()
|
||||
// .SingleInstance();
|
||||
|
||||
builder.RegisterGeneric(typeof(Logger<>))
|
||||
.As(typeof(ILogger<>))
|
||||
.SingleInstance();
|
||||
builder.RegisterGeneric(typeof(Logger<>))
|
||||
.As(typeof(ILogger<>))
|
||||
.SingleInstance();
|
||||
|
||||
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
||||
});
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
||||
});
|
||||
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
});
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
});
|
||||
|
||||
|
||||
ContainerBuilder = builder;
|
||||
}
|
||||
ContainerBuilder = builder;
|
||||
}
|
||||
|
||||
[TestCleanup]
|
||||
public void CleanUp()
|
||||
{
|
||||
Trace.Flush();
|
||||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||
telemetryClient.Flush();
|
||||
[TestCleanup]
|
||||
public void CleanUp()
|
||||
{
|
||||
Trace.Flush();
|
||||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||
telemetryClient.Flush();
|
||||
|
||||
if (Container != null)
|
||||
{
|
||||
Container.Dispose();
|
||||
Container = null;
|
||||
}
|
||||
}
|
||||
if (Container != null)
|
||||
{
|
||||
Container.Dispose();
|
||||
Container = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue