Exemplo n.º 1
0
        public void LoadKeyValuePairsFromAzureEnvironment()
        {
            var dict = 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(dict);

            Assert.Equal(9, envConfigSrc.Data.Count);
            Assert.Equal("TestAppName", envConfigSrc.Data["APPSETTING_AppName"]);
            Assert.False(envConfigSrc.Data.ContainsKey("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"]);
        }
        public void LoadKeyValuePairsFromAzureEnvironment()
        {
            var dict = 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(dict);

            string value;
            Assert.Equal("TestAppName", envConfigSrc.Get("APPSETTING_AppName"));
            Assert.False(envConfigSrc.TryGet("AppName", out value));
            Assert.Equal("CustomConnStr", envConfigSrc.Get("Data:db1:ConnectionString"));
            Assert.Equal("SQLConnStr", envConfigSrc.Get("Data:db2:ConnectionString"));
            Assert.Equal("System.Data.SqlClient", envConfigSrc.Get("Data:db2:ProviderName"));
            Assert.Equal("MySQLConnStr", envConfigSrc.Get("Data:db3:ConnectionString"));
            Assert.Equal("MySql.Data.MySqlClient", envConfigSrc.Get("Data:db3:ProviderName"));
            Assert.Equal("SQLAzureConnStr", envConfigSrc.Get("Data:db4:ConnectionString"));
            Assert.Equal("System.Data.SqlClient", envConfigSrc.Get("Data:db4:ProviderName"));
            Assert.Equal("CommonEnvValue", envConfigSrc.Get("CommonEnv"));
        }
Exemplo n.º 3
0
        public void HandleEmptyEnvironmentDictionaryProperly()
        {
            var dict         = new Hashtable();
            var envConfigSrc = new EnvironmentVariablesConfigurationSource();

            envConfigSrc.Load(dict);

            Assert.Equal(0, envConfigSrc.Data.Count);
        }
Exemplo n.º 4
0
        public void ThrowExceptionWhenKeyIsDuplicatedInAzureEnvironment()
        {
            var dict = new Hashtable()
            {
                { "Data:db2:ConnectionString", "CommonEnvValue" },
                { "SQLCONNSTR_db2", "SQLConnStr" },
            };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource();
            var expectedMsg  = "An item with the same key has already been added.";

            var exception = Assert.Throws <ArgumentException>(() => envConfigSrc.Load(dict));

            Assert.Equal(expectedMsg, exception.Message);
        }
Exemplo n.º 5
0
        public void LoadKeyValuePairsFromEnvironmentDictionaryWithPrefix()
        {
            var dict = new Hashtable()
            {
                { "DefaultConnection:ConnectionString", "TestConnectionString" },
                { "DefaultConnection:Provider", "SqlClient" },
                { "Inventory:ConnectionString", "AnotherTestConnectionString" },
                { "Inventory:Provider", "MySql" }
            };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource("DefaultConnection:");

            envConfigSrc.Load(dict);

            Assert.Equal(2, envConfigSrc.Data.Count);
            Assert.Equal("TestConnectionString", envConfigSrc.Data["ConnectionString"]);
            Assert.Equal("SqlClient", envConfigSrc.Data["Provider"]);
        }
        public void LoadKeyValuePairsFromEnvironmentDictionary()
        {
            var dict = new Hashtable()
                {
                    {"DefaultConnection:ConnectionString", "TestConnectionString"},
                    {"DefaultConnection:Provider", "SqlClient"},
                    {"Inventory:ConnectionString", "AnotherTestConnectionString"},
                    {"Inventory:Provider", "MySql"}
                };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource();

            envConfigSrc.Load(dict);

            Assert.Equal("TestConnectionString", envConfigSrc.Get("defaultconnection:ConnectionString"));
            Assert.Equal("SqlClient", envConfigSrc.Get("DEFAULTCONNECTION:PROVIDER"));
            Assert.Equal("AnotherTestConnectionString", envConfigSrc.Get("Inventory:CONNECTIONSTRING"));
            Assert.Equal("MySql", envConfigSrc.Get("Inventory:Provider"));
        }
Exemplo n.º 7
0
        public void LoadKeyValuePairsFromEnvironmentDictionary()
        {
            var dict = new Hashtable()
            {
                { "DefaultConnection:ConnectionString", "TestConnectionString" },
                { "DefaultConnection:Provider", "SqlClient" },
                { "Inventory:ConnectionString", "AnotherTestConnectionString" },
                { "Inventory:Provider", "MySql" }
            };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource();

            envConfigSrc.Load(dict);

            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"]);
        }
        public void LoadKeyValuePairsFromAzureEnvironmentWithPrefix()
        {
            var dict = new Hashtable()
                {
                    {"CUSTOMCONNSTR_db1", "CustomConnStr"},
                    {"SQLCONNSTR_db2", "SQLConnStr"},
                    {"MYSQLCONNSTR_db3", "MySQLConnStr"},
                    {"SQLAZURECONNSTR_db4", "SQLAzureConnStr"},
                    {"CommonEnv", "CommonEnvValue"},
                };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource("Data:");

            envConfigSrc.Load(dict);

            Assert.Equal("CustomConnStr", envConfigSrc.Get("db1:ConnectionString"));
            Assert.Equal("SQLConnStr", envConfigSrc.Get("db2:ConnectionString"));
            Assert.Equal("System.Data.SqlClient", envConfigSrc.Get("db2:ProviderName"));
            Assert.Equal("MySQLConnStr", envConfigSrc.Get("db3:ConnectionString"));
            Assert.Equal("MySql.Data.MySqlClient", envConfigSrc.Get("db3:ProviderName"));
            Assert.Equal("SQLAzureConnStr", envConfigSrc.Get("db4:ConnectionString"));
            Assert.Equal("System.Data.SqlClient", envConfigSrc.Get("db4:ProviderName"));
        }
Exemplo n.º 9
0
        public void LoadKeyValuePairsFromAzureEnvironmentWithPrefix()
        {
            var dict = new Hashtable()
            {
                { "CUSTOMCONNSTR_db1", "CustomConnStr" },
                { "SQLCONNSTR_db2", "SQLConnStr" },
                { "MYSQLCONNSTR_db3", "MySQLConnStr" },
                { "SQLAZURECONNSTR_db4", "SQLAzureConnStr" },
                { "CommonEnv", "CommonEnvValue" },
            };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource("Data:");

            envConfigSrc.Load(dict);

            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"]);
        }
        public void LoadKeyValuePairsFromEnvironmentDictionaryWithPrefix()
        {
            var dict = new Hashtable()
                {
                    {"DefaultConnection:ConnectionString", "TestConnectionString"},
                    {"DefaultConnection:Provider", "SqlClient"},
                    {"Inventory:ConnectionString", "AnotherTestConnectionString"},
                    {"Inventory:Provider", "MySql"}
                };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource("DefaultConnection:");

            envConfigSrc.Load(dict);

            Assert.Equal("TestConnectionString", envConfigSrc.Get("ConnectionString"));
            Assert.Equal("SqlClient", envConfigSrc.Get("Provider"));
        }
        public void ThrowExceptionWhenKeyIsDuplicatedInAzureEnvironment()
        {
            var dict = new Hashtable()
                {
                    {"Data:db2:ConnectionString", "CommonEnvValue"},
                    {"SQLCONNSTR_db2", "SQLConnStr"},
                };
            var envConfigSrc = new EnvironmentVariablesConfigurationSource();
            var expectedMsg = "An item with the same key has already been added.";

            var exception = Assert.Throws<ArgumentException>(() => envConfigSrc.Load(dict));

            Assert.Equal(expectedMsg, exception.Message);
        }