-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed problem during using multiple json files with collection values…
… they are not overriden
- Loading branch information
Showing
4 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters