diff --git a/test/NetLah.Extensions.Configuration.Test/ConfigurationBuilderBuilderTest.cs b/test/NetLah.Extensions.Configuration.Test/ConfigurationBuilderBuilderTest.cs index e89a950..f7bb254 100644 --- a/test/NetLah.Extensions.Configuration.Test/ConfigurationBuilderBuilderTest.cs +++ b/test/NetLah.Extensions.Configuration.Test/ConfigurationBuilderBuilderTest.cs @@ -935,7 +935,7 @@ public void ConfigurationSourceDevelopmentSecrets_NoSources() { var configuration = ConfigurationBuilderBuilder.Create() .WithEnvironment("Development") - .WithAddPostConfiguration(builder => builder.AddConfigurationSource()) + .WithConfigurationSource() .BuildConfigurationRoot(); AssertProviders(configuration, new[] { @@ -955,4 +955,159 @@ public void ConfigurationSourceDevelopmentSecrets_NoSources() AssertDevelopment(configuration); } + [Fact] + public void ConfigurationSourceProduction_configJson() + { + var configuration = ConfigurationBuilderBuilder.Create( + new string[] { + "/ConfigurationSource:0=Other-Config-Source/config.json" + }) + .WithConfigurationSource() + .BuildConfigurationRoot(); + + AssertProviders(configuration, new[] { + "JsonConfigurationProvider", + "JsonConfigurationProvider", + "ChainedConfigurationProvider", + "EnvironmentVariablesConfigurationProvider", + "CommandLineConfigurationProvider", + }, new[] { + "appsettings.json", + "appsettings.Production.json", + null, + null, + null, + }); + + Assert.Equal("EnvironmentProductionValue1", configuration["EnvironmentKey"]); + Assert.Equal("Other-Config-Source/config.json", configuration["MainKey"]); + Assert.Equal("config.json", configuration["JsonSection:Other-Config-Source"]); + } + + [Fact] + public void ConfigurationSourceProduction_configJsonIni() + { + var configuration = ConfigurationBuilderBuilder.Create( + new string[] { + "/ConfigurationSource:0=Other-Config-Source/config.json", + "/ConfigurationSource:1=Other-Config-Source/config.ini", + }) + .WithConfigurationSource() + .BuildConfigurationRoot(); + + AssertProviders(configuration, new[] { + "JsonConfigurationProvider", + "JsonConfigurationProvider", + "ChainedConfigurationProvider", + "EnvironmentVariablesConfigurationProvider", + "CommandLineConfigurationProvider", + }, new[] { + "appsettings.json", + "appsettings.Production.json", + null, + null, + null, + }); + + Assert.Equal("EnvironmentProductionValue1", configuration["EnvironmentKey"]); + Assert.Equal("Other-Config-Source/config.ini", configuration["MainKey"]); + Assert.Equal("config.json", configuration["JsonSection:Other-Config-Source"]); + Assert.Equal("config.ini", configuration["IniSection:Other-Config-Source"]); + } + + [Fact] + public void ConfigurationSourceProduction_configIniJson() + { + var configuration = ConfigurationBuilderBuilder.Create( + new string[] { + "/ConfigurationSource:0=Other-Config-Source/config.ini", + "/ConfigurationSource:1=Other-Config-Source/config.json", + }) + .WithConfigurationSource() + .BuildConfigurationRoot(); + + AssertProviders(configuration, new[] { + "JsonConfigurationProvider", + "JsonConfigurationProvider", + "ChainedConfigurationProvider", + "EnvironmentVariablesConfigurationProvider", + "CommandLineConfigurationProvider", + }, new[] { + "appsettings.json", + "appsettings.Production.json", + null, + null, + null, + }); + + Assert.Equal("EnvironmentProductionValue1", configuration["EnvironmentKey"]); + Assert.Equal("Other-Config-Source/config.json", configuration["MainKey"]); + Assert.Equal("config.json", configuration["JsonSection:Other-Config-Source"]); + Assert.Equal("config.ini", configuration["IniSection:Other-Config-Source"]); + } + + [Fact] + public void ConfigurationSourceProduction_configIniJsonXml() + { + var configuration = ConfigurationBuilderBuilder.Create( + new string[] { + "/ConfigurationSource:0=Other-Config-Source/config.ini", + "/ConfigurationSource:1=Other-Config-Source/config.json", + "/ConfigurationSource:2=Other-Config-Source/config.xml", + }) + .WithConfigurationSource() + .BuildConfigurationRoot(); + + AssertProviders(configuration, new[] { + "JsonConfigurationProvider", + "JsonConfigurationProvider", + "ChainedConfigurationProvider", + "EnvironmentVariablesConfigurationProvider", + "CommandLineConfigurationProvider", + }, new[] { + "appsettings.json", + "appsettings.Production.json", + null, + null, + null, + }); + + Assert.Equal("EnvironmentProductionValue1", configuration["EnvironmentKey"]); + Assert.Equal("Other-Config-Source/config.xml", configuration["MainKey"]); + Assert.Equal("config.json", configuration["JsonSection:Other-Config-Source"]); + Assert.Equal("config.ini", configuration["IniSection:Other-Config-Source"]); + Assert.Equal("config.xml", configuration["XmlSection:Other-Config-Source"]); + } + + [Fact] + public void ConfigurationSource_Transform() + { + var configuration = ConfigurationBuilderBuilder.Create( + new string[] { + "/configSrc:0=appsettings.Transform.json", + }) + .WithConfigurationSource("configSrc") + .WithTransformConfiguration() + .BuildConfigurationRoot(); + + AssertProviders(configuration, new[] { + "JsonConfigurationProvider", + "JsonConfigurationProvider", + "ChainedConfigurationProvider", + "EnvironmentVariablesConfigurationProvider", + "CommandLineConfigurationProvider", + "TransformConfigurationProvider", + }, new[] { + "appsettings.json", + "appsettings.Production.json", + null, + null, + null, + null, + }); + + AssertProduction(configuration); + AssertTransform(configuration); + } + } diff --git a/test/NetLah.Extensions.Configuration.Test/NetLah.Extensions.Configuration.Test.csproj b/test/NetLah.Extensions.Configuration.Test/NetLah.Extensions.Configuration.Test.csproj index deef18a..405962f 100644 --- a/test/NetLah.Extensions.Configuration.Test/NetLah.Extensions.Configuration.Test.csproj +++ b/test/NetLah.Extensions.Configuration.Test/NetLah.Extensions.Configuration.Test.csproj @@ -15,7 +15,8 @@ - + + diff --git a/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.ini b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.ini new file mode 100644 index 0000000..d3179d9 --- /dev/null +++ b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.ini @@ -0,0 +1,4 @@ +MainKey = "Other-Config-Source/config.ini" + +[IniSection] +Other-Config-Source = config.ini diff --git a/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.json b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.json new file mode 100644 index 0000000..e14b95e --- /dev/null +++ b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.json @@ -0,0 +1,6 @@ +{ + "MainKey": "Other-Config-Source/config.json", + "JsonSection": { + "Other-Config-Source": "config.json" + } +} diff --git a/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.xml b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.xml new file mode 100644 index 0000000..d4c2191 --- /dev/null +++ b/test/NetLah.Extensions.Configuration.Test/Other-Config-Source/config.xml @@ -0,0 +1,7 @@ + + + Other-Config-Source/config.xml + + config.xml + + diff --git a/test/NetLah.Extensions.Configuration.Test/appsettings.ini b/test/NetLah.Extensions.Configuration.Test/appsettings.ini index 0874a9d..ecd111d 100644 --- a/test/NetLah.Extensions.Configuration.Test/appsettings.ini +++ b/test/NetLah.Extensions.Configuration.Test/appsettings.ini @@ -1,4 +1,4 @@ IniKey1="ini Value2" [IniSection3:Section4] -Key5 = Value6 \ No newline at end of file +Key5 = Value6 diff --git a/test/NetLah.Extensions.Configuration.Test/appsettings.xml b/test/NetLah.Extensions.Configuration.Test/appsettings.xml index 8ce213f..3b9f52c 100644 --- a/test/NetLah.Extensions.Configuration.Test/appsettings.xml +++ b/test/NetLah.Extensions.Configuration.Test/appsettings.xml @@ -4,4 +4,4 @@ Value5 - \ No newline at end of file +