Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aloneguid/config
Browse files Browse the repository at this point in the history
  • Loading branch information
aloneguid committed Jul 29, 2020
2 parents 56413f7 + aa583fb commit 784b293
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
4 changes: 2 additions & 2 deletions doc/Stores_InMemory.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ To configure the store:

```csharp
IMySettings settings = new ConfigurationBuilder<IMySettings>()
.UseInMemory()
.UseInMemoryDictionary()
.Build();
```

The store supports reading and writing, and stores configuration in the application memory. When application restarts all the setting values are lost. You may want to use this store for debugging or testing, other that that it has no real applications.

## Collections

Collections are supported by using the [flatline syntax](flatline.md).
Collections are supported by using the [flatline syntax](flatline.md).
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 784b293

Please sign in to comment.