public static IConfigurationBuilder AddYamlFile(this IConfigurationBuilder builder, IFileProvider provider, string path, bool optional, bool reloadOnChange) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrEmpty(path)) { throw new ArgumentException("InvalidFilePath", nameof(path)); } if (provider == null && Path.IsPathRooted(path)) { provider = new PhysicalFileProvider(Path.GetDirectoryName(path)); path = Path.GetFileName(path); } var source = new YamlConfigurationSource { FileProvider = provider, Path = path, Optional = optional, ReloadOnChange = reloadOnChange }; builder.Add(source); return builder; }
public static IConfigurationBuilder AddYamlFile( this IConfigurationBuilder builder, Action<YamlConfigurationSource> configureSource) { var source = new YamlConfigurationSource(); configureSource(source); builder.Add(source); return builder; }
public void LoadMethodCanHandleEmptyValue() { var yaml = @"name:"; var yamlConfigSrc = new YamlConfigurationSource(TestStreamHelpers.ArbitraryFilePath); yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml)); Assert.Equal(string.Empty, yamlConfigSrc.Get("name")); }
public void NonObjectRootIsInvalid() { var yaml = @"test"; var yamlConfigSrc = new YamlConfigurationSource("Foo"); var exception = Assert.Throws<FormatException>( () => yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml))); Assert.NotNull(exception.Message); }
public void SupportAndIgnoreComments() { var yaml = @"# Comments # Comments name: test #foo address: street: Something street # Comments zipcode: 12345"; var yamlConfigSrc = new YamlConfigurationSource("Foo"); yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml)); Assert.Equal("test", yamlConfigSrc.Get("name")); Assert.Equal("Something street", yamlConfigSrc.Get("address:street")); Assert.Equal("12345", yamlConfigSrc.Get("address:zipcode")); }
public void LoadKeyValuePairsFromValidYaml() { var yaml = @" firstname: test test.last.name: last.name residential.address: street.name: Something street zipcode: 12345"; var yamlConfigSrc = new YamlConfigurationSource(TestStreamHelpers.ArbitraryFilePath); yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml.TrimStart())); Assert.Equal("test", yamlConfigSrc.Get("firstname")); Assert.Equal("last.name", yamlConfigSrc.Get("test.last.name")); Assert.Equal("Something street", yamlConfigSrc.Get("residential.address:STREET.name")); Assert.Equal("12345", yamlConfigSrc.Get("residential.address:zipcode")); }
public void Foo() { var yaml = @"--- name: Default dataproviders: entityframework-sql: connectionstring: Foo table-prefix: 12345 entityframework-inmemory: ..."; File.WriteAllText(_tempFolderName, yaml); var yamlConfigSrc = new YamlConfigurationSource(_tempFolderName); var root = new ConfigurationBuilder(yamlConfigSrc).Build(); var settings = new ShellSettings(root); //Assert.Equal(, settings.DataProviders.First()) }
void IShellSettingsManager.SaveSettings(ShellSettings shellSettings) { if (shellSettings == null) throw new ArgumentNullException(nameof(shellSettings)); if (string.IsNullOrWhiteSpace(shellSettings.Name)) throw new ArgumentException( "The Name property of the supplied ShellSettings object is null or empty; the settings cannot be saved.", nameof(shellSettings.Name)); _logger.LogInformation("Saving ShellSettings for tenant '{0}'", shellSettings.Name); var tenantPath = _appDataFolder.MapPath(_appDataFolder.Combine("Sites", shellSettings.Name)); var configurationSource = new YamlConfigurationSource( _appDataFolder.Combine(tenantPath, string.Format(SettingsFileNameFormat, "txt")), false); foreach (var key in shellSettings.RootConfiguration.GetChildren()) { configurationSource.Set(key.Key, key.Value); } configurationSource.Commit(); _logger.LogInformation("Saved ShellSettings for tenant '{0}'", shellSettings.Name); }
public void SupportForMultiple() { var yaml = @"--- name: test #foo address: home: street: Some Home Address zipcode: 12345 work: street: Some Work Address zipcode: 54321 ..."; var yamlConfigSrc = new YamlConfigurationSource(TestStreamHelpers.ArbitraryFilePath); yamlConfigSrc.Load(TestStreamHelpers.StringToStream(yaml)); Assert.Equal("Some Home Address", yamlConfigSrc.Get("address:home:street")); Assert.Equal("12345", yamlConfigSrc.Get("address:home:zipcode")); Assert.Equal("Some Work Address", yamlConfigSrc.Get("address:work:street")); Assert.Equal("54321", yamlConfigSrc.Get("address:work:zipcode")); }