Skip to content

Commit

Permalink
fixed problem during using multiple json files with collection values…
Browse files Browse the repository at this point in the history
… they are not overriden
  • Loading branch information
Mathias Feitzinger authored and aloneguid committed Jul 29, 2020
1 parent f3f96b4 commit aa583fb
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Config.Net.Json/Stores/JsonFileConfigStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public string Read(string key)
return arrayToken.Count.ToString();
}

return "0";
return null;
}

return GetStringValue(valueToken);
Expand Down
76 changes: 76 additions & 0 deletions src/Config.Net.Tests/MultipleConfigurationFilesTest.cs
Original file line number Diff line number Diff line change
@@ -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<IArrayElement> Creds { get; }
}

public interface IArrayElement
{
string Username { get; }

string Password { get; }
}

public MultipleConfigurationFilesTest()
{
var configurationBuilder = new ConfigurationBuilder<IRootElement>();
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);
}
}
}
2 changes: 1 addition & 1 deletion src/Config.Net.Yaml/Stores/YamlFileConfigStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private string GetResult(YamlNode node, bool isLength)
return sequenceNode.Count().ToString();
}

return "0";
return null;
}

if (node is YamlScalarNode scalar)
Expand Down
2 changes: 1 addition & 1 deletion src/Config.Net/Stores/IniFileConfigStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class IniFileConfigStore : IConfigStore

/// <summary>
///
/// </summary>
/// </summary>r
/// <param name="name">File does not have to exist, however it will be created as soon as you
/// try to write to it</param>
public IniFileConfigStore(string name, bool isFilePath, bool parseInlineComments)
Expand Down

0 comments on commit aa583fb

Please sign in to comment.