diff --git a/doc/Stores_InMemory.md b/doc/Stores_InMemory.md index 73a59bf..eb07c81 100644 --- a/doc/Stores_InMemory.md +++ b/doc/Stores_InMemory.md @@ -4,7 +4,7 @@ To configure the store: ```csharp IMySettings settings = new ConfigurationBuilder() - .UseInMemory() + .UseInMemoryDictionary() .Build(); ``` @@ -12,4 +12,4 @@ The store supports reading and writing, and stores configuration in the applicat ## Collections -Collections are supported by using the [flatline syntax](flatline.md). \ No newline at end of file +Collections are supported by using the [flatline syntax](flatline.md). diff --git a/src/Config.Net.Json/Stores/JsonFileConfigStore.cs b/src/Config.Net.Json/Stores/JsonFileConfigStore.cs index 6c1d37d..f869453 100644 --- a/src/Config.Net.Json/Stores/JsonFileConfigStore.cs +++ b/src/Config.Net.Json/Stores/JsonFileConfigStore.cs @@ -69,7 +69,7 @@ public string Read(string key) return arrayToken.Count.ToString(); } - return "0"; + return null; } return GetStringValue(valueToken); diff --git a/src/Config.Net.Tests/MultipleConfigurationFilesTest.cs b/src/Config.Net.Tests/MultipleConfigurationFilesTest.cs new file mode 100644 index 0000000..d46712e --- /dev/null +++ b/src/Config.Net.Tests/MultipleConfigurationFilesTest.cs @@ -0,0 +1,76 @@ +using System.IO; +using Config.Net.Json.Stores; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using Config.Net.Json.Stores; +using Config.Net.Stores; +using Xunit; + +namespace Config.Net.Tests +{ + public class MultipleConfigurationFilesTest : AbstractTestFixture + { + private IRootElement ConfigInterface { get; } + + private const string configBasic = @"{ +'KeyA': 'basic', +'KeyB': 'basic', + 'Creds': [ + { + 'Username': 'user', + 'Password': 'debug' + } +] +}"; + + private const string configOverride = @"{ +'KeyB': 'override', +}"; + + public interface IRootElement + { + string KeyA { get; } + string KeyB { get; } + IEnumerable Creds { get; } + } + + public interface IArrayElement + { + string Username { get; } + + string Password { get; } + } + + public MultipleConfigurationFilesTest() + { + var configurationBuilder = new ConfigurationBuilder(); + configurationBuilder + .UseJsonString(configOverride) + .UseJsonString(configBasic); + ConfigInterface = configurationBuilder.Build(); + } + + [Fact] + public void Read_Correct_Key() + { + Assert.Equal("basic", ConfigInterface.KeyA); + Assert.Equal("override", ConfigInterface.KeyB); + } + + [Fact] + public void Read_Creds_IsNotEmpty() + { + Assert.NotEmpty(ConfigInterface.Creds); + } + + [Fact] + public void Read_Correct_Creds() + { + Assert.Equal("user", ConfigInterface.Creds.ToArray().FirstOrDefault()?.Username); + Assert.Equal("debug", ConfigInterface.Creds.FirstOrDefault()?.Password); + } + } +} \ No newline at end of file diff --git a/src/Config.Net.Yaml/Stores/YamlFileConfigStore.cs b/src/Config.Net.Yaml/Stores/YamlFileConfigStore.cs index ef7c2c1..b68544a 100644 --- a/src/Config.Net.Yaml/Stores/YamlFileConfigStore.cs +++ b/src/Config.Net.Yaml/Stores/YamlFileConfigStore.cs @@ -126,7 +126,7 @@ private string GetResult(YamlNode node, bool isLength) return sequenceNode.Count().ToString(); } - return "0"; + return null; } if (node is YamlScalarNode scalar) diff --git a/src/Config.Net/Stores/IniFileConfigStore.cs b/src/Config.Net/Stores/IniFileConfigStore.cs index 489551f..51b6284 100644 --- a/src/Config.Net/Stores/IniFileConfigStore.cs +++ b/src/Config.Net/Stores/IniFileConfigStore.cs @@ -16,7 +16,7 @@ class IniFileConfigStore : IConfigStore /// /// - /// + /// r /// File does not have to exist, however it will be created as soon as you /// try to write to it public IniFileConfigStore(string name, bool isFilePath, bool parseInlineComments)