Beispiel #1
0
        public void GetBooleanValue(string key, string value, bool expected)
        {
            IConfiguration config = null;
            Assert.DoesNotThrow(() => config = Configuration.SystemDefault);
            Assert.IsNotNull(config);

            ConfigKey configKey = new ConfigKey(key, typeof(string));
            Assert.DoesNotThrow(() => config.SetKey(configKey));
            Assert.DoesNotThrow(() => config.SetValue(configKey, value));

            ConfigValue configValue = null;
            Assert.DoesNotThrow(() => configValue = config.GetValue(configKey));
            Assert.IsNotNull(value);
            Assert.IsNotNull(configValue.Value);

            bool bValue = false;
            Assert.DoesNotThrow(() => bValue = configValue.ToType<bool>());
            Assert.AreEqual(expected, bValue);
        }
Beispiel #2
0
        public void GetValueAsInt32()
        {
            IConfiguration config = null;
            Assert.DoesNotThrow(() => config = Configuration.SystemDefault);
            Assert.IsNotNull(config);

            ConfigKey key = new ConfigKey("test.oneKey", "one", typeof(string));
            Assert.DoesNotThrow(() => config.SetKey(key));
            Assert.DoesNotThrow(() => config.SetValue(key, "22"));

            ConfigValue value = null;
            Assert.DoesNotThrow(() => value = config.GetValue(key));
            Assert.IsNotNull(value);
            Assert.IsNotNull(value.Value);

            int iValue = -1;
            Assert.DoesNotThrow(() => iValue = value.ToType<int>());
            Assert.AreEqual(22, iValue);
        }
Beispiel #3
0
        public void GetEnumValue(object value, TestEnum expected)
        {
            IConfiguration config = null;
            Assert.DoesNotThrow(() => config = Configuration.SystemDefault);
            Assert.IsNotNull(config);

            ConfigKey configKey = new ConfigKey("test", typeof(TestEnum));
            Assert.DoesNotThrow(() => config.SetKey(configKey));
            Assert.DoesNotThrow(() => config.SetValue(configKey, value));

            ConfigValue configValue = null;
            Assert.DoesNotThrow(() => configValue = config.GetValue(configKey));

            TestEnum enumValue = new TestEnum();
            Assert.DoesNotThrow(() => enumValue = configValue.ToType<TestEnum>());
            Assert.AreEqual(expected, enumValue);
        }
Beispiel #4
0
        /// <inheritdoc/>
        public void SetValue(ConfigKey key, object value)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            if (!keys.ContainsKey(key.Name))
                keys[key.Name] = key;

            values[key.Name] = new ConfigValue(key, value);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public void SetKey(ConfigKey key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            keys[key.Name] = key;
        }
Beispiel #6
0
        /// <inheritdoc/>
        public ConfigValue GetValue(ConfigKey key)
        {
            if (key == null)
                throw new ArgumentNullException("key");

            ConfigValue value;
            if (values.TryGetValue(key.Name, out value))
                return value;

            if (!isRoot && Parent != null &&
                ((value = Parent.GetValue(key)) != null))
                return value;

            return new ConfigValue(key, key.DefaultValue);
        }
 private void SetValue(IConfiguration config, string propKey, string value)
 {
     var configKey = config.GetKey(propKey);
     if (configKey != null) {
         var propValue = ConvertValueTo(value, configKey.ValueType);
         config.SetValue(configKey, propValue);
     } else {
         configKey = new ConfigKey(propKey, typeof (string));
         config.SetKey(configKey);
         config.SetValue(configKey, value);
     }
 }