public void ValueWithNullKey()
        {
            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 <ArgumentNullException>(() => configuration.Value <string>(null));

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

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

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

            sub.Verify(s => s.HasValueFor(It.IsAny <ConfigurationKeyBase>()), Times.Once());
            sub.Verify(s => s.Value(It.IsAny <ConfigurationKey <string> >()), Times.Once());
        }
        public void ValueWithMultipleConfigurationsAndUnknownKey()
        {
            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(false)
                .Verifiable();
                sub2.Setup(s => s.Value(It.IsAny <ConfigurationKey <string> >()))
                .Verifiable();
            }

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

            Assert.Throws <ArgumentException>(() => 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.Never());
        }