public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName, IConfigurationFormatter formatter) { using (var source = new FileConfigurationSource(fileName)) { return(builder.Load(source, formatter)); } }
public static IConfigurationBuilder LoadFile(this IConfigurationBuilder builder, string fileName, IConfigurationFormatter formatter) { using (var source = new FileConfigurationSource(fileName)) { return builder.Load(source, formatter); } }
public static ISystemBuilder UseFileConfiguration(this ISystemBuilder builder, string filePath, IConfigurationFormatter formatter) { var config = new Data.Configuration.Configuration(); using (var source = new FileConfigurationSource(filePath)) { formatter.LoadInto(config, source.InputStream); } return(builder.UseConfiguration(config)); }
public void LoadProperties() { var dbConfig = new Configuration(); var path = Path.Combine(Environment.CurrentDirectory, FileName); using (var source = new FileConfigurationSource(path)) { dbConfig.Load(source, new PropertiesConfigurationFormatter()); } Assert.AreEqual(2, dbConfig.GetKeys().Count()); var firstSetting = dbConfig.GetValue("first-setting"); Assert.IsNotNull(firstSetting); Assert.IsInstanceOf<string>(firstSetting); Assert.AreEqual("one", firstSetting); var secondSetting = dbConfig.GetValue("second"); Assert.IsNotNull(secondSetting); Assert.IsInstanceOf<string>(secondSetting); Assert.AreEqual("345.33", secondSetting); }
public void LoadFromFile_Properties() { var filePath = Path.Combine(Environment.CurrentDirectory, "db.config"); var config = new Configuration(); using (var source = new FileConfigurationSource(filePath)) { config.Load(source, new PropertiesConfigurationFormatter()); } Assert.AreEqual(2, config.Count()); var keys = config.GetKeys().ToArray(); Assert.IsNotEmpty(keys); Assert.AreEqual("system.configKey", keys.First()); var configValue = config.GetValue("db.name"); Assert.IsNotNull(configValue); Assert.IsInstanceOf <string>(configValue); Assert.AreEqual("testdb", (string)configValue); }
public void LoadProperties() { var dbConfig = new Configuration(); var path = Path.Combine(Environment.CurrentDirectory, FileName); using (var source = new FileConfigurationSource(path)) { dbConfig.Load(source, new PropertiesConfigurationFormatter()); } Assert.AreEqual(2, dbConfig.GetKeys().Count()); var firstSetting = dbConfig.GetValue("first-setting"); Assert.IsNotNull(firstSetting); Assert.IsInstanceOf <string>(firstSetting); Assert.AreEqual("one", firstSetting); var secondSetting = dbConfig.GetValue("second"); Assert.IsNotNull(secondSetting); Assert.IsInstanceOf <string>(secondSetting); Assert.AreEqual("345.33", secondSetting); }
public static void Save(this IConfiguration config, ConfigurationLevel level, string fileName, IConfigurationFormatter formatter) { using (var source = new FileConfigurationSource(fileName)) { config.Save(source, level, formatter); } }
public void LoadFromFile_Properties() { var filePath = Path.Combine(Environment.CurrentDirectory, "db.config"); var config = new Configuration(); using (var source = new FileConfigurationSource(filePath)) { config.Load(source, new PropertiesConfigurationFormatter()); } Assert.AreEqual(2, config.Count()); var keys = config.GetKeys().ToArray(); Assert.IsNotEmpty(keys); Assert.AreEqual("system.configKey", keys.First()); var configValue = config.GetValue("db.name"); Assert.IsNotNull(configValue); Assert.IsInstanceOf<string>(configValue); Assert.AreEqual("testdb", (string)configValue); }