Esempio n. 1
0
        public void AsEnumerateFlattensIntoDictionaryTest(bool removePath)
        {
            // Arrange
            var dic1 = new Dictionary <string, string>()
            {
                { "Mem1", "Value1" },
                { "Mem1:", "NoKeyValue1" },
                { "Mem1:KeyInMem1", "ValueInMem1" },
                { "Mem1:KeyInMem1:Deep1", "ValueDeep1" }
            };
            var dic2 = new Dictionary <string, string>()
            {
                { "Mem2", "Value2" },
                { "Mem2:", "NoKeyValue2" },
                { "Mem2:KeyInMem2", "ValueInMem2" },
                { "Mem2:KeyInMem2:Deep2", "ValueDeep2" }
            };
            var dic3 = new Dictionary <string, string>()
            {
                { "Mem3", "Value3" },
                { "Mem3:", "NoKeyValue3" },
                { "Mem3:KeyInMem3", "ValueInMem3" },
                { "Mem3:KeyInMem3:Deep3", "ValueDeep3" }
            };
            var memConfigSrc1 = new MemoryConfigurationSource {
                InitialData = dic1
            };
            var memConfigSrc2 = new MemoryConfigurationSource {
                InitialData = dic2
            };
            var memConfigSrc3 = new MemoryConfigurationSource {
                InitialData = dic3
            };

            var config = new ConfigurationManager();
            IConfigurationBuilder configurationBuilder = config;

            // Act
            configurationBuilder.Add(memConfigSrc1);
            configurationBuilder.Add(memConfigSrc2);
            configurationBuilder.Add(memConfigSrc3);
            var dict = config.AsEnumerable(makePathsRelative: removePath).ToDictionary(k => k.Key, v => v.Value);

            // Assert
            Assert.Equal("Value1", dict["Mem1"]);
            Assert.Equal("NoKeyValue1", dict["Mem1:"]);
            Assert.Equal("ValueDeep1", dict["Mem1:KeyInMem1:Deep1"]);
            Assert.Equal("ValueInMem2", dict["Mem2:KeyInMem2"]);
            Assert.Equal("Value2", dict["Mem2"]);
            Assert.Equal("NoKeyValue2", dict["Mem2:"]);
            Assert.Equal("ValueDeep2", dict["Mem2:KeyInMem2:Deep2"]);
            Assert.Equal("Value3", dict["Mem3"]);
            Assert.Equal("NoKeyValue3", dict["Mem3:"]);
            Assert.Equal("ValueInMem3", dict["Mem3:KeyInMem3"]);
            Assert.Equal("ValueDeep3", dict["Mem3:KeyInMem3:Deep3"]);
        }
Esempio n. 2
0
        public void NewConfigurationRootMayBeBuiltFromExistingWithDuplicateKeys()
        {
            var configurationRoot = new ConfigurationManager();

            configurationRoot.AddInMemoryCollection(new Dictionary <string, string>
            {
                { "keya:keyb", "valueA" },
            });
            configurationRoot.AddInMemoryCollection(new Dictionary <string, string>
            {
                { "KEYA:KEYB", "valueB" },
            });

            var newConfigurationRoot = new ConfigurationManager();

            newConfigurationRoot.AddInMemoryCollection(configurationRoot.AsEnumerable());

            Assert.Equal("valueB", newConfigurationRoot["keya:keyb"]);
        }