Esempio n. 1
0
        public void ProcessEnvHigherThanUserConfig()
        {
            const string retryKey = "Retry";
            const string envName  = "ENV_FOR_RETRY";
            var          config   = new SimpleTypedConfig <int>(retryKey, "", -1, envName);

            var path      = Path.GetRandomFileName();
            var dataStore = new MockDataStore();

            dataStore.WriteFile(path,
                                @"{
    ""Az"": {
        ""Retry"": 100
    }
}");
            var env = new MockEnvironmentVariableProvider();

            env.Set(envName, "10", System.EnvironmentVariableTarget.Process);

            IConfigManager icm = GetConfigManager(
                new InitSettings()
            {
                DataStore = dataStore,
                Path      = path,
                EnvironmentVariableProvider = env
            },
                config);

            Assert.Equal(10, icm.GetConfigValue <int>(retryKey));
        }
Esempio n. 2
0
        public void ProcessConfigHigherThanProcessEnv()
        {
            const string retryKey = "Retry";
            const string envName  = "ENV_FOR_RETRY";
            var          config   = new SimpleTypedConfig <int>(retryKey, "", -1, envName);
            var          env      = new MockEnvironmentVariableProvider();

            env.Set(envName, "10", System.EnvironmentVariableTarget.Process);
            IConfigManager icm = GetConfigManager(
                new InitSettings()
            {
                EnvironmentVariableProvider = env
            },
                config);

            icm.UpdateConfig(new UpdateConfigOptions(retryKey, 100, ConfigScope.Process));
            Assert.Equal(100, icm.GetConfigValue <int>(retryKey));
        }
Esempio n. 3
0
        public void ShouldNotThrowWhenEnvVarIsWrong()
        {
            const string key                 = "FromEnv";
            const string envKey              = "ENV_VAR_FOR_CONFIG";
            const int    defaultValue        = -1;
            var          config              = new SimpleTypedConfig <int>(key, "", defaultValue, envKey);
            const bool   valueWithWrongType  = true;
            IEnvironmentVariableProvider env = new MockEnvironmentVariableProvider();

            env.Set(envKey, valueWithWrongType.ToString());
            var configurationManager = GetConfigManager(
                new InitSettings()
            {
                EnvironmentVariableProvider = env
            },
                config);

            Assert.Equal(defaultValue, configurationManager.GetConfigValue <int>(key));
        }
Esempio n. 4
0
        public void CanGetFromEnvironmentVar()
        {
            const string key    = "FromEnv";
            const string envKey = "ENV_VAR_FOR_CONFIG";
            var          config = new SimpleTypedConfig <int>(key, "", -1, envKey);
            const int    value  = 20;

            IEnvironmentVariableProvider env = new MockEnvironmentVariableProvider();

            env.Set(envKey, value.ToString());
            var configurationManager = GetConfigManager(
                new InitSettings()
            {
                EnvironmentVariableProvider = env
            },
                config);

            Assert.Equal(value, configurationManager.GetConfigValue <int>(key));
        }