protected virtual TestConfigurationSource CreateSource()
        {
            ConfigurationSourceConfig   sourceConfig = ConfigurationSources.NewConfig("test-source");
            Dictionary <string, string> properties   = new Dictionary <string, string>();

            properties["exist"]  = "ok";
            properties["exist2"] = "ok2";
            properties["exist3"] = "ok3";
            properties["exist4"] = "ok4";
            properties["exist5"] = "ok5";
            TestConfigurationSource source = new TestConfigurationSource(sourceConfig, properties);

            Console.WriteLine("source config: " + sourceConfig + "\n");
            return(source);
        }
Ejemplo n.º 2
0
        public virtual void TestGetPropertiesMultipleSource()
        {
            TestConfigurationSource        source1 = CreateSource();
            TestDynamicConfigurationSource source2 = CreateDynamicSource();
            IConfigurationManager          manager = CreateManager(
                new Dictionary <int, IConfigurationSource>()
            {
                { 1, source1 },
                { 2, source2 },
            });
            PropertyConfig <string, string> propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>()
                                                             .SetKey("not-exist").Build();
            IProperty <string, string> property = manager.GetProperty(propertyConfig);

            Console.WriteLine("property: " + property + "\n");
            Assert.Null(property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("not-exist2")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("default", property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("exist")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok.2", property.Value);

            propertyConfig = ConfigurationProperties.NewConfigBuilder <string, string>().SetKey("exist5")
                             .SetDefaultValue("default").Build();
            property = manager.GetProperty(propertyConfig);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok5", property.Value);

            source2.SetPropertyValue("exist5", "ok5.2");
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok5.2", property.Value);

            source2.SetPropertyValue("exist5", null);
            Console.WriteLine("property: " + property + "\n");
            Assert.Equal("ok5", property.Value);
        }