wip
This commit is contained in:
parent
0f1a345216
commit
e73f428c49
6 changed files with 96 additions and 144 deletions
|
|
@ -116,7 +116,7 @@ namespace Core.Logging
|
||||||
{ "ResponseCode", req.ResponseCode },
|
{ "ResponseCode", req.ResponseCode },
|
||||||
{ "Duration", req.Duration.TotalMilliseconds }
|
{ "Duration", req.Duration.TotalMilliseconds }
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var prop in req.Properties)
|
foreach (var prop in req.Properties)
|
||||||
{
|
{
|
||||||
seqEvent.Add(prop.Key, prop.Value);
|
seqEvent.Add(prop.Key, prop.Value);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,11 @@ namespace Tests.ConfigurationTests
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class JsonConfigurationProviderTests : TestFixture
|
public class JsonConfigurationProviderTests : TestFixture
|
||||||
{
|
{
|
||||||
public JsonConfigurationProviderTests() : base("ConfigurationTests") { }
|
const string _testFolder = "ConfigurationTests/";
|
||||||
|
|
||||||
|
public JsonConfigurationProviderTests() : base(_testFolder) { }
|
||||||
|
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void GetSection_ShouldReturnCorrectFeatureSection()
|
public void GetSection_ShouldReturnCorrectFeatureSection()
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +25,7 @@ namespace Tests.ConfigurationTests
|
||||||
}") as JToken;
|
}") as JToken;
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -44,8 +48,8 @@ namespace Tests.ConfigurationTests
|
||||||
};
|
};
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actualFeature = builder.GetSection("Feature").ToObject<Feature>();
|
var actualFeature = builder.GetSection("Feature").ToObject<Feature>();
|
||||||
|
|
@ -64,8 +68,8 @@ namespace Tests.ConfigurationTests
|
||||||
var expectedFeature = "123";
|
var expectedFeature = "123";
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High");
|
var actualFeature = builder.GetSection("AnotherSetting").Get<string>("Thresholds:High");
|
||||||
|
|
@ -83,8 +87,8 @@ namespace Tests.ConfigurationTests
|
||||||
var expected = "SHA256";
|
var expected = "SHA256";
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actual = builder["Authentication"];
|
var actual = builder["Authentication"];
|
||||||
|
|
@ -99,8 +103,8 @@ namespace Tests.ConfigurationTests
|
||||||
var expectedFeature = 22;
|
var expectedFeature = 22;
|
||||||
|
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit");
|
var actualFeature = builder.GetSection("AnotherSetting:Temperature").Get<int>("Indoor:Max:Limit");
|
||||||
|
|
@ -115,8 +119,8 @@ namespace Tests.ConfigurationTests
|
||||||
var expectedFeature = true;
|
var expectedFeature = true;
|
||||||
|
|
||||||
var configRoot = new ConfigurationBuilder()
|
var configRoot = new ConfigurationBuilder()
|
||||||
.AddJsonFile("appconfiguration.dev.json")
|
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
|
||||||
.AddSmartConfig()
|
.AddSmartConfig()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
|
||||||
|
|
@ -8,92 +8,92 @@ using Microsoft.Extensions.Logging;
|
||||||
using Core.Configurations.JsonConfigProvider;
|
using Core.Configurations.JsonConfigProvider;
|
||||||
namespace Tests
|
namespace Tests
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Act as base class for tests. Avoids duplication of test setup code
|
/// Act as base class for tests. Avoids duplication of test setup code
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public abstract partial class TestFixture
|
public abstract partial class TestFixture
|
||||||
{
|
{
|
||||||
private readonly string _configurationFilePath;
|
private readonly string _configurationFilePath;
|
||||||
|
|
||||||
protected IContainer Container { get; private set; }
|
protected IContainer Container { get; private set; }
|
||||||
protected ContainerBuilder ContainerBuilder { get; private set; }
|
protected ContainerBuilder ContainerBuilder { get; private set; }
|
||||||
|
|
||||||
public virtual IConfigurationRoot Configuration()
|
public virtual IConfigurationRoot Configuration()
|
||||||
{
|
{
|
||||||
var configuration = new ConfigurationBuilder()
|
var configuration = new ConfigurationBuilder()
|
||||||
.AddJsonFile($"{_configurationFilePath}appconfiguration.dev.json")
|
.AddJsonFile($"{_configurationFilePath}appconfiguration.dev.json")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return configuration;
|
return configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TestFixture()
|
protected TestFixture() : this(null) { }
|
||||||
{
|
public TestFixture(string configurationFilePath)
|
||||||
CreateContainerBuilder();
|
{
|
||||||
Container = ContainerBuilder.Build();
|
if (configurationFilePath is not null)
|
||||||
}
|
_configurationFilePath = configurationFilePath?.TrimEnd('/') + "/";
|
||||||
public TestFixture(string configurationFilePath) : this()
|
|
||||||
{
|
|
||||||
_configurationFilePath = configurationFilePath;
|
|
||||||
}
|
|
||||||
protected virtual void CreateContainerBuilder()
|
|
||||||
{
|
|
||||||
IConfigurationRoot configuration = Configuration();
|
|
||||||
|
|
||||||
//var logger = new LoggerConfiguration()
|
CreateContainerBuilder();
|
||||||
// .MinimumLevel.Verbose()
|
Container = ContainerBuilder.Build();
|
||||||
// .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
|
}
|
||||||
// .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Error)
|
protected virtual void CreateContainerBuilder()
|
||||||
// .WriteTo.Seq("http://localhost:5341", apiKey: "Gt8hS9ClGNfOCAdswDlW")
|
{
|
||||||
// .WriteTo.ApplicationInsights(configuration.Get<string>("ApplicationInsights:ConnectionString"),
|
IConfigurationRoot configuration = Configuration();
|
||||||
// TelemetryConverter.Traces)
|
|
||||||
// .Enrich.FromLogContext()
|
|
||||||
// .Enrich.WithMachineName()
|
|
||||||
// .CreateLogger();
|
|
||||||
|
|
||||||
//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");
|
//Log.Logger = logger;
|
||||||
var builder = new ContainerBuilder();
|
|
||||||
|
//Log.Logger.Verbose("Is thos work");
|
||||||
|
var builder = new ContainerBuilder();
|
||||||
|
|
||||||
|
|
||||||
//builder.Register(c => new SerilogLoggerFactory(logger))
|
//builder.Register(c => new SerilogLoggerFactory(logger))
|
||||||
// .As<ILoggerFactory>()
|
// .As<ILoggerFactory>()
|
||||||
// .SingleInstance();
|
// .SingleInstance();
|
||||||
|
|
||||||
builder.RegisterGeneric(typeof(Logger<>))
|
builder.RegisterGeneric(typeof(Logger<>))
|
||||||
.As(typeof(ILogger<>))
|
.As(typeof(ILogger<>))
|
||||||
.SingleInstance();
|
.SingleInstance();
|
||||||
|
|
||||||
|
|
||||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||||
{
|
{
|
||||||
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
ConnectionString = configuration.GetConnectionString("DefaultConnection")
|
||||||
});
|
});
|
||||||
|
|
||||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||||
{
|
{
|
||||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ContainerBuilder = builder;
|
ContainerBuilder = builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCleanup]
|
[TestCleanup]
|
||||||
public void CleanUp()
|
public void CleanUp()
|
||||||
{
|
{
|
||||||
Trace.Flush();
|
Trace.Flush();
|
||||||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||||
telemetryClient.Flush();
|
telemetryClient.Flush();
|
||||||
|
|
||||||
if (Container != null)
|
if (Container != null)
|
||||||
{
|
{
|
||||||
Container.Dispose();
|
Container.Dispose();
|
||||||
Container = null;
|
Container = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="xappconfiguration.dev.json">
|
<None Update="appconfiguration.dev.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="ConfigurationTests\appconfiguration.dev.json">
|
<None Update="ConfigurationTests\appconfiguration.dev.json">
|
||||||
|
|
|
||||||
8
Tests/appconfiguration.dev.json
Normal file
8
Tests/appconfiguration.dev.json
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
||||||
|
},
|
||||||
|
"ApplicationInsights": {
|
||||||
|
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
{
|
|
||||||
"AllowedHosts": "*",
|
|
||||||
"ConnectionStrings": {
|
|
||||||
"DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptmain;User Id=sathumper;Password=3911;"
|
|
||||||
},
|
|
||||||
"ApplicationInsights": {
|
|
||||||
"ConnectionString": "InstrumentationKey=6d2e76ee-5343-4691-a5e3-81add43cb584;IngestionEndpoint=https://northeurope-0.in.applicationinsights.azure.com/"
|
|
||||||
},
|
|
||||||
"Authentication": "SHA256",
|
|
||||||
"Feature": {
|
|
||||||
"Enabled": true,
|
|
||||||
"RolloutPercentage": 25,
|
|
||||||
"AllowedUserGroups": [ "beta" ]
|
|
||||||
},
|
|
||||||
"AnotherSetting": {
|
|
||||||
|
|
||||||
"Thresholds": {
|
|
||||||
"High": "123",
|
|
||||||
"Low": "-1"
|
|
||||||
},
|
|
||||||
"Temperature": {
|
|
||||||
|
|
||||||
"Indoor": {
|
|
||||||
"Max": { "Limit": 22 },
|
|
||||||
"Min": { "Limit": 18 }
|
|
||||||
},
|
|
||||||
"Outdoor": {
|
|
||||||
"Max": { "Limit": 12 },
|
|
||||||
"Min": { "Limit": 9 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Serilog": {
|
|
||||||
"MinimumLevel": {
|
|
||||||
"Default": "Information",
|
|
||||||
"Override": {
|
|
||||||
"Microsoft": "Warning",
|
|
||||||
"System": "Warning"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"WriteTo": [
|
|
||||||
{
|
|
||||||
"Name": "Seq",
|
|
||||||
"Args": {
|
|
||||||
"serverUrl": "http://localhost:5341",
|
|
||||||
"apiKey": ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Enrich": [
|
|
||||||
"WithMachineName",
|
|
||||||
"WithThreadId",
|
|
||||||
"WithProcessId",
|
|
||||||
"WithEnvironmentName"
|
|
||||||
],
|
|
||||||
"Properties": {
|
|
||||||
"Application": "PlanTempus"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue