예제 #1
0
        private TestConfig()
        {
            _cstr = Environment.GetEnvironmentVariable("CUSTOMCONNSTR_TestAccount");
            const string cliConfigPath = "App.config";
            const string vsConfigPath = "..\\..\\App.config";
            if (_cstr == null)
            {
                var configuration = new Configuration();
                if (File.Exists(cliConfigPath))
                {
                    configuration.AddXmlFile(cliConfigPath);
                }
                else if (File.Exists(vsConfigPath))
                {
                    configuration.AddXmlFile(vsConfigPath);
                }

                if (configuration.TryGet("TestAccount:ConnectionString", out _cstr))
                {
                    _cstr = _cstr.Trim();
                }
            }
        }
예제 #2
0
        public void LoadAndCombineKeyValuePairsFromDifferentConfigurationSources()
        {
            // Arrange
            var config = new Configuration();

            // Act
            config.AddIniFile(_iniConfigFilePath);
            config.AddJsonFile(_jsonConfigFilePath);
            config.AddXmlFile(_xmlConfigFilePath);
            var memConfigSrc = new MemoryConfigurationSource(_memConfigContent);

            config.Add(memConfigSrc);

            // Assert
            Assert.Equal(24, CountAllEntries(config));

            Assert.Equal("IniValue1", config.Get("IniKey1"));
            Assert.Equal("IniValue2", config.Get("IniKey2:IniKey3"));
            Assert.Equal("IniValue3", config.Get("IniKey2:IniKey4"));
            Assert.Equal("IniValue4", config.Get("IniKey2:IniKey5:IniKey6"));
            Assert.Equal("IniValue5", config.Get("CommonKey1:CommonKey2:IniKey7"));

            Assert.Equal("JsonValue1", config.Get("JsonKey1"));
            Assert.Equal("JsonValue2", config.Get("Json.Key2:JsonKey3"));
            Assert.Equal("JsonValue3", config.Get("Json.Key2:Json.Key4"));
            Assert.Equal("JsonValue4", config.Get("Json.Key2:JsonKey5:JsonKey6"));
            Assert.Equal("JsonValue5", config.Get("CommonKey1:CommonKey2:JsonKey7"));

            Assert.Equal("XmlValue1", config.Get("XmlKey1"));
            Assert.Equal("XmlValue2", config.Get("XmlKey2:XmlKey3"));
            Assert.Equal("XmlValue3", config.Get("XmlKey2:XmlKey4"));
            Assert.Equal("XmlValue4", config.Get("XmlKey2:XmlKey5:XmlKey6"));
            Assert.Equal("XmlValue5", config.Get("CommonKey1:CommonKey2:XmlKey7"));

            Assert.Equal("MemValue1", config["MemKey1"]);
            Assert.Equal("MemValue2", config["MemKey2:MemKey3"]);
            Assert.Equal("MemValue3", config["MemKey2:MemKey4"]);
            Assert.Equal("MemValue4", config["MemKey2:MemKey5:MemKey6"]);
            Assert.Equal("MemValue5", config["CommonKey1:CommonKey2:MemKey7"]);

            Assert.Equal("MemValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
        }
예제 #3
0
        public void CanOverrideValuesWithNewConfigurationSource()
        {
            // Arrange
            var config = new Configuration();

            // Act & Assert
            config.AddIniFile(_iniConfigFilePath);
            Assert.Equal("IniValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));

            config.AddJsonFile(_jsonConfigFilePath);
            Assert.Equal("JsonValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));

            config.AddXmlFile(_xmlConfigFilePath);
            Assert.Equal("XmlValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));

            var memConfigSrc = new MemoryConfigurationSource(_memConfigContent);

            config.Add(memConfigSrc);
            Assert.Equal("MemValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));
        }
예제 #4
0
파일: Startup.cs 프로젝트: moljac/Ph4ct3x
		public void Configure(IApplicationBuilder app)
        {
			// For more information on how to configure your application, 
			// visit http://go.microsoft.com/fwlink/?LinkID=398940

			// Setup configuration sources
			Configuration configuration = new Configuration();

			configuration.AddJsonFile("config.json");
			configuration.AddIniFile("config.ini");
			// this cannot be accessed if XML fomratters were removed
			configuration.AddXmlFile("config.xml");
			configuration.AddEnvironmentVariables();

			string url_home = configuration.Get<string>("UrlLogo");

			app.UseMvc();
			app.UseWelcomePage();

			return;
		}
예제 #5
0
        public void CanCommitChangeBackToLastConfigFile()
        {
            // Arrange
            var config = new Configuration();

            config.AddIniFile(_iniConfigFilePath);
            config.AddJsonFile(_jsonConfigFilePath);
            config.AddXmlFile(_xmlConfigFilePath);
            config.Set("CommonKey1:CommonKey2:CommonKey3:CommonKey4", "NewValue");

            // Act
            config.Commit();

            // Assert
            Assert.Equal(_iniConfigFileContent, File.ReadAllText(_iniConfigFilePath));

            Assert.Equal(_jsonConfigFileContent, File.ReadAllText(_jsonConfigFilePath));

            var updatedXmlContent = _xmlConfigFileContent.Replace("XmlValue6", "NewValue");

            Assert.Equal(updatedXmlContent, File.ReadAllText(_xmlConfigFilePath));
        }
예제 #6
0
        public void CanSetValuesAndReloadValues()
        {
            // Arrange
            var config = new Configuration();

            config.AddIniFile(_iniConfigFilePath);
            config.AddJsonFile(_jsonConfigFilePath);
            config.AddXmlFile(_xmlConfigFilePath);

            // Act & Assert
            // Set value with Set() method
            config.Set("CommonKey1:CommonKey2:CommonKey3:CommonKey4", "NewValue");

            // All config sources must be updated
            foreach (var src in config)
            {
                Assert.Equal("NewValue",
                             (src as BaseConfigurationSource).Data["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
            }

            // Recover values by reloading
            config.Reload();
            Assert.Equal("XmlValue6", config.Get("CommonKey1:CommonKey2:CommonKey3:CommonKey4"));

            // Set value with indexer
            config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"] = "NewValue";

            // All config sources must be updated
            foreach (var src in config)
            {
                Assert.Equal("NewValue",
                             (src as BaseConfigurationSource).Data["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
            }

            // Recover values by reloading
            config.Reload();
            Assert.Equal("XmlValue6", config["CommonKey1:CommonKey2:CommonKey3:CommonKey4"]);
        }