Add unit tests for EnvironmentVariablesConfigurationSource class
This commit is contained in:
Родитель
793b63eb05
Коммит
a079b3da99
|
@ -17,6 +17,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Configurat
|
|||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.ConfigurationModel.Xml.Test", "test\Microsoft.AspNet.ConfigurationModel.Xml.Test\Microsoft.AspNet.ConfigurationModel.Xml.Test.kproj", "{0786C785-944A-4423-96A6-4E7BFDB4A1B0}"
|
||||
EndProject
|
||||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.ConfigurationModel.Test", "test\Microsoft.AspNet.ConfigurationModel.Test\Microsoft.AspNet.ConfigurationModel.Test.kproj", "{8777C77E-CA2A-42C1-90CD-2EA9CBF28937}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
|
@ -39,6 +41,9 @@ Global
|
|||
{0786C785-944A-4423-96A6-4E7BFDB4A1B0}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{0786C785-944A-4423-96A6-4E7BFDB4A1B0}.Release|x86.ActiveCfg = Release|x86
|
||||
{0786C785-944A-4423-96A6-4E7BFDB4A1B0}.Release|x86.Build.0 = Release|x86
|
||||
{8777C77E-CA2A-42C1-90CD-2EA9CBF28937}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{8777C77E-CA2A-42C1-90CD-2EA9CBF28937}.Release|x86.ActiveCfg = Release|x86
|
||||
{8777C77E-CA2A-42C1-90CD-2EA9CBF28937}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -49,5 +54,6 @@ Global
|
|||
{1BEC97C1-56B9-4B2B-A95A-C0DF72F1E96A} = {F141E2D0-F9B8-4ADB-A19A-7B6FF4CA19A1}
|
||||
{AE8F8C20-9ED9-4A16-9565-27DF77683789} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
||||
{0786C785-944A-4423-96A6-4E7BFDB4A1B0} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
||||
{8777C77E-CA2A-42C1-90CD-2EA9CBF28937} = {B54371FF-B920-46C8-8D55-6B19DBB43EBF}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -0,0 +1,127 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNet.ConfigurationModel.Sources
|
||||
{
|
||||
public class EnvironmentVariablesConfigurationSourceTest
|
||||
{
|
||||
[Fact]
|
||||
public void LoadKeyValuePairsFromEnvironmentDictionary()
|
||||
{
|
||||
var dic = new Hashtable()
|
||||
{
|
||||
{"DefaultConnection:ConnectionString", "TestConnectionString"},
|
||||
{"DefaultConnection:Provider", "SqlClient"},
|
||||
{"Inventory:ConnectionString", "AnotherTestConnectionString"},
|
||||
{"Inventory:Provider", "MySql"}
|
||||
};
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource();
|
||||
|
||||
envConfigSrc.Load(dic);
|
||||
|
||||
Assert.Equal(4, envConfigSrc.Data.Count);
|
||||
Assert.Equal("TestConnectionString", envConfigSrc.Data["DefaultConnection:ConnectionString"]);
|
||||
Assert.Equal("SqlClient", envConfigSrc.Data["DefaultConnection:Provider"]);
|
||||
Assert.Equal("AnotherTestConnectionString", envConfigSrc.Data["Inventory:ConnectionString"]);
|
||||
Assert.Equal("MySql", envConfigSrc.Data["Inventory:Provider"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadKeyValuePairsFromEnvironmentDictionaryWithPrefix()
|
||||
{
|
||||
var dic = new Hashtable()
|
||||
{
|
||||
{"DefaultConnection:ConnectionString", "TestConnectionString"},
|
||||
{"DefaultConnection:Provider", "SqlClient"},
|
||||
{"Inventory:ConnectionString", "AnotherTestConnectionString"},
|
||||
{"Inventory:Provider", "MySql"}
|
||||
};
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource("DefaultConnection:");
|
||||
|
||||
envConfigSrc.Load(dic);
|
||||
|
||||
Assert.Equal(2, envConfigSrc.Data.Count);
|
||||
Assert.Equal("TestConnectionString", envConfigSrc.Data["ConnectionString"]);
|
||||
Assert.Equal("SqlClient", envConfigSrc.Data["Provider"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadKeyValuePairsFromAzureEnvironment()
|
||||
{
|
||||
var dic = new Hashtable()
|
||||
{
|
||||
{"APPSETTING_AppName", "TestAppName"},
|
||||
{"CUSTOMCONNSTR_db1", "CustomConnStr"},
|
||||
{"SQLCONNSTR_db2", "SQLConnStr"},
|
||||
{"MYSQLCONNSTR_db3", "MySQLConnStr"},
|
||||
{"SQLAZURECONNSTR_db4", "SQLAzureConnStr"},
|
||||
{"CommonEnv", "CommonEnvValue"},
|
||||
};
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource();
|
||||
|
||||
envConfigSrc.Load(dic);
|
||||
|
||||
Assert.Equal(9, envConfigSrc.Data.Count);
|
||||
Assert.Equal("TestAppName", envConfigSrc.Data["AppName"]);
|
||||
Assert.Equal("CustomConnStr", envConfigSrc.Data["Data:db1:ConnectionString"]);
|
||||
Assert.Equal("SQLConnStr", envConfigSrc.Data["Data:db2:ConnectionString"]);
|
||||
Assert.Equal("System.Data.SqlClient", envConfigSrc.Data["Data:db2:ProviderName"]);
|
||||
Assert.Equal("MySQLConnStr", envConfigSrc.Data["Data:db3:ConnectionString"]);
|
||||
Assert.Equal("MySql.Data.MySqlClient", envConfigSrc.Data["Data:db3:ProviderName"]);
|
||||
Assert.Equal("SQLAzureConnStr", envConfigSrc.Data["Data:db4:ConnectionString"]);
|
||||
Assert.Equal("System.Data.SqlClient", envConfigSrc.Data["Data:db4:ProviderName"]);
|
||||
Assert.Equal("CommonEnvValue", envConfigSrc.Data["CommonEnv"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LoadKeyValuePairsFromAzureEnvironmentWithPrefix()
|
||||
{
|
||||
var dic = new Hashtable()
|
||||
{
|
||||
{"APPSETTING_AppName", "TestAppName"},
|
||||
{"CUSTOMCONNSTR_db1", "CustomConnStr"},
|
||||
{"SQLCONNSTR_db2", "SQLConnStr"},
|
||||
{"MYSQLCONNSTR_db3", "MySQLConnStr"},
|
||||
{"SQLAZURECONNSTR_db4", "SQLAzureConnStr"},
|
||||
{"CommonEnv", "CommonEnvValue"},
|
||||
};
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource("Data:");
|
||||
|
||||
envConfigSrc.Load(dic);
|
||||
|
||||
Assert.Equal(7, envConfigSrc.Data.Count);
|
||||
Assert.Equal("CustomConnStr", envConfigSrc.Data["db1:ConnectionString"]);
|
||||
Assert.Equal("SQLConnStr", envConfigSrc.Data["db2:ConnectionString"]);
|
||||
Assert.Equal("System.Data.SqlClient", envConfigSrc.Data["db2:ProviderName"]);
|
||||
Assert.Equal("MySQLConnStr", envConfigSrc.Data["db3:ConnectionString"]);
|
||||
Assert.Equal("MySql.Data.MySqlClient", envConfigSrc.Data["db3:ProviderName"]);
|
||||
Assert.Equal("SQLAzureConnStr", envConfigSrc.Data["db4:ConnectionString"]);
|
||||
Assert.Equal("System.Data.SqlClient", envConfigSrc.Data["db4:ProviderName"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ThrowExceptionWhenKeyIsDuplicatedInAzureEnvironment()
|
||||
{
|
||||
var dic = new Hashtable()
|
||||
{
|
||||
{"Data:db2:ConnectionString", "CommonEnvValue"},
|
||||
{"SQLCONNSTR_db2", "SQLConnStr"},
|
||||
};
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource();
|
||||
|
||||
Assert.ThrowsAny<Exception>(() => envConfigSrc.Load(dic));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleEmptyEnvironmentDictionaryProperly()
|
||||
{
|
||||
var dic = new Hashtable();
|
||||
var envConfigSrc = new EnvironmentVariablesConfigurationSource();
|
||||
|
||||
envConfigSrc.Load(dic);
|
||||
|
||||
Assert.Equal(0, envConfigSrc.Data.Count);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
<Content Include="Project.json" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="EnvironmentVariablesConfigurationSourceTest.cs" />
|
||||
<Compile Include="IniFileConfigurationSourceTest.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\ProjectK\Microsoft.Web.ProjectK.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
},
|
||||
"k10": {
|
||||
"dependencies": {
|
||||
"System.Collections": "4.0.0.0",
|
||||
"System.IO": "4.0.0.0",
|
||||
"System.Runtime": "4.0.20.0",
|
||||
"System.Threading.Tasks": "4.0.10.0"
|
||||
|
|
Загрузка…
Ссылка в новой задаче