This commit is contained in:
Janus C. H. Knudsen 2025-02-19 14:21:40 +01:00
parent 0f1a345216
commit e73f428c49
6 changed files with 96 additions and 144 deletions

View file

@ -9,7 +9,11 @@ namespace Tests.ConfigurationTests
[TestClass]
public class JsonConfigurationProviderTests : TestFixture
{
public JsonConfigurationProviderTests() : base("ConfigurationTests") { }
const string _testFolder = "ConfigurationTests/";
public JsonConfigurationProviderTests() : base(_testFolder) { }
[TestMethod]
public void GetSection_ShouldReturnCorrectFeatureSection()
{
@ -21,7 +25,7 @@ namespace Tests.ConfigurationTests
}") as JToken;
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.Build();
// Act
@ -44,7 +48,7 @@ namespace Tests.ConfigurationTests
};
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.Build();
// Act
@ -64,7 +68,7 @@ namespace Tests.ConfigurationTests
var expectedFeature = "123";
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.Build();
// Act
@ -83,7 +87,7 @@ namespace Tests.ConfigurationTests
var expected = "SHA256";
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.Build();
// Act
@ -99,7 +103,7 @@ namespace Tests.ConfigurationTests
var expectedFeature = 22;
var builder = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.Build();
// Act
@ -115,7 +119,7 @@ namespace Tests.ConfigurationTests
var expectedFeature = true;
var configRoot = new ConfigurationBuilder()
.AddJsonFile("appconfiguration.dev.json")
.AddJsonFile($"{_testFolder}appconfiguration.dev.json")
.AddSmartConfig()
.Build();

View file

@ -28,15 +28,15 @@ namespace Tests
return configuration;
}
protected TestFixture()
protected TestFixture() : this(null) { }
public TestFixture(string configurationFilePath)
{
if (configurationFilePath is not null)
_configurationFilePath = configurationFilePath?.TrimEnd('/') + "/";
CreateContainerBuilder();
Container = ContainerBuilder.Build();
}
public TestFixture(string configurationFilePath) : this()
{
_configurationFilePath = configurationFilePath;
}
protected virtual void CreateContainerBuilder()
{
IConfigurationRoot configuration = Configuration();

View file

@ -27,7 +27,7 @@
</ItemGroup>
<ItemGroup>
<None Update="xappconfiguration.dev.json">
<None Update="appconfiguration.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ConfigurationTests\appconfiguration.dev.json">

View 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/"
}
}

View file

@ -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"
}
}
}