public void HasValueWithMultipleConfigurationsAndUnknownKey()
        {
            var key  = new ConfigurationKey <string>("a");
            var sub1 = new Mock <IConfiguration>();
            {
                sub1.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(false)
                .Verifiable();
            }

            var sub2 = new Mock <IConfiguration>();
            {
                sub2.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(false)
                .Verifiable();
            }

            var configuration = new HierarchicalConfiguration(
                new IConfiguration[]
            {
                sub1.Object,
                sub2.Object
            });

            Assert.IsFalse(configuration.HasValueFor(key));
            sub1.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
            sub2.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
        }
Пример #2
0
        public void ValueWithUnknownKey()
        {
            var key           = new ConfigurationKey <int>("b");
            var configuration = new ConstantConfiguration(new Dictionary <ConfigurationKeyBase, object>());

            Assert.Throws <ArgumentException>(() => configuration.Value(key));
        }
        public void Create()
        {
            var name = "a";
            var key  = new ConfigurationKey <string>(name);

            Assert.AreEqual(name, key.Name);
            Assert.AreEqual(typeof(string), key.TranslateTo);
        }
Пример #4
0
        public void HasValueWithUnknownKey()
        {
            var key = new ConfigurationKey <string>("a");

            var configuration = new ConstantConfiguration(new Dictionary <ConfigurationKeyBase, object>());

            Assert.IsFalse(configuration.HasValueFor(key));
        }
Пример #5
0
        public void HasValueWithKnownKey()
        {
            var key = new ConfigurationKey <string>("a");

            var configuration = new ConstantConfiguration(
                new Dictionary <ConfigurationKeyBase, object>
            {
                [key] = 10
            });

            Assert.IsTrue(configuration.HasValueFor(key));
        }
Пример #6
0
        public void ValueWithKnownKey()
        {
            var value         = "a";
            var key           = new ConfigurationKey <string>("b");
            var configuration = new ConstantConfiguration(
                new Dictionary <ConfigurationKeyBase, object>
            {
                [key] = value
            });

            Assert.AreSame(value, configuration.Value(key));
        }
Пример #7
0
        public void HasValueWithNullKey()
        {
            var key = new ConfigurationKey <string>("string");

            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.IsFalse(configuration.HasValueFor(null));
        }
Пример #8
0
        public void ValueWithUnknownKey()
        {
            var key = new ConfigurationKey <string>("unknown");

            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.Throws <ArgumentException>(() => configuration.Value(key));
        }
Пример #9
0
        public void HasValueWithUnknownKey()
        {
            var key = new ConfigurationKey <string>("unknown");

            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.IsFalse(configuration.HasValueFor(key));
        }
Пример #10
0
        public void ValueWithNullKey()
        {
            var key = new ConfigurationKey <string>("a");

            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.Throws <ArgumentNullException>(() => configuration.Value <string>(null));
        }
Пример #11
0
        public void ValueAsCharacterWithKnownKey()
        {
            var value = 'a';

            var key           = new ConfigurationKey <char>("char");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #12
0
        public void ValueAsUnsignedShortWithKnownKey()
        {
            ushort value = 10;

            var key           = new ConfigurationKey <ushort>("ushort");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #13
0
        public void ValueAsUnsignedLongWithKnownKey()
        {
            var value = 10UL;

            var key           = new ConfigurationKey <ulong>("ulong");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #14
0
        public void ValueAsStringWithKnownKey()
        {
            var value = "string";

            var key           = new ConfigurationKey <string>("string");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #15
0
        public void ValueAsIntWithKnownKey()
        {
            var value = 10;

            var key           = new ConfigurationKey <int>("int");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #16
0
        public void ValueAsDoubleWithKnownKey()
        {
            var value = 10.0d;

            var key           = new ConfigurationKey <double>("double");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
Пример #17
0
        public void ValueAsBooleanWithKnownKey()
        {
            var value = true;

            var key           = new ConfigurationKey <bool>("bool");
            var configuration = new ConsulConfiguration(
                new List <ConfigurationKeyBase>
            {
                key
            },
                _subConfiguration);

            Assert.AreEqual(value, configuration.Value(key));
        }
        public void HasValueWithKnownKey()
        {
            var key = new ConfigurationKey <string>("a");
            var sub = new Mock <IConfiguration>();
            {
                sub.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(true)
                .Verifiable();
            }

            var configuration = new HierarchicalConfiguration(new IConfiguration[] { sub.Object });

            Assert.IsTrue(configuration.HasValueFor(key));

            sub.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
        }
        public void ValueWithUnknownKey()
        {
            var key = new ConfigurationKey <string>("b");
            var sub = new Mock <IConfiguration>();
            {
                sub.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(false)
                .Verifiable();
                sub.Setup(s => s.Value(It.IsAny <ConfigurationKey <string> >()))
                .Verifiable();
            }

            var configuration = new HierarchicalConfiguration(new IConfiguration[] { sub.Object });

            Assert.Throws <ArgumentException>(() => configuration.Value(key));

            sub.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
            sub.Verify(s => s.Value(It.IsAny <ConfigurationKey <string> >()), Times.Never());
        }
        public void ValueWithMultipleConfigurationsAndKnownKey()
        {
            var value = "a";
            var key   = new ConfigurationKey <string>("b");
            var sub1  = new Mock <IConfiguration>();
            {
                sub1.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(false)
                .Verifiable();
                sub1.Setup(s => s.Value(It.IsAny <ConfigurationKey <string> >()))
                .Verifiable();
            }

            var sub2 = new Mock <IConfiguration>();
            {
                sub2.Setup(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()))
                .Returns(true)
                .Verifiable();
                sub2.Setup(s => s.Value(It.IsAny <ConfigurationKey <string> >()))
                .Returns(value)
                .Verifiable();
            }

            var configuration = new HierarchicalConfiguration(
                new IConfiguration[]
            {
                sub1.Object,
                sub2.Object
            });

            Assert.AreSame(value, configuration.Value(key));

            sub1.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
            sub1.Verify(s => s.Value(It.IsAny <ConfigurationKey <string> >()), Times.Never());

            sub2.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
            sub2.Verify(s => s.Value(It.IsAny <ConfigurationKey <string> >()), Times.Once());
        }
 /// <summary>
 /// Returns the value for the given configuration key.
 /// </summary>
 /// <typeparam name="T">The type of the return value.</typeparam>
 /// <param name="key">The configuration key.</param>
 /// <returns>
 /// The desired value.
 /// </returns>
 public T Value <T>(ConfigurationKey <T> key)
 {
     return(Value <T>((ConfigurationKeyBase)key));
 }