-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
430 additions
and
1,124 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
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,5 @@ | ||
## 5.3.0 | ||
|
||
### Improvements | ||
|
||
- Upgraded dependent libraries. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
202 changes: 92 additions & 110 deletions
202
src/Config.Net.Tests/Stores/JsonFileCOnfigStoreTest.cs
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 |
---|---|---|
@@ -1,117 +1,99 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using Config.Net.Stores; | ||
using Xunit; | ||
using YamlDotNet.Core.Tokens; | ||
|
||
namespace Config.Net.Tests.Stores | ||
{ | ||
public class JsonFileConfigStoreTest : AbstractTestFixture, IDisposable | ||
{ | ||
private string _path; | ||
private JsonConfigStore _store; | ||
|
||
public JsonFileConfigStoreTest() | ||
{ | ||
_path = Path.Combine(BuildDir.FullName, "TestData", "sample.json"); | ||
_store = new JsonConfigStore(_path, true); | ||
} | ||
|
||
[Fact] | ||
public void Read_inline_property() | ||
{ | ||
string key = _store.Read("ApplicationInsights.InstrumentationKey"); | ||
|
||
Assert.NotNull(key); | ||
} | ||
|
||
[Fact] | ||
public void Write_inline_property_reads_back() | ||
{ | ||
if (!_store.CanWrite) return; | ||
|
||
string key = "ApplicationInsights.InstrumentationKey"; | ||
|
||
_store.Write(key, "123"); | ||
|
||
Assert.Equal("123", _store.Read(key)); | ||
} | ||
|
||
[Fact] | ||
public void Write_new_value_hierarchically() | ||
{ | ||
if (!_store.CanWrite) return; | ||
|
||
string key = "One.Two.Three"; | ||
|
||
_store.Write(key, "111"); | ||
|
||
Assert.Equal("111", _store.Read(key)); | ||
} | ||
|
||
[Fact] | ||
public void AliasesOnCollections() | ||
{ | ||
IMyConfigUsingAliases myConfig = new ConfigurationBuilder<IMyConfigUsingAliases>() | ||
.UseConfigStore(_store) | ||
.Build(); | ||
|
||
Assert.NotNull(myConfig.Credentials); | ||
foreach (ICredsWithAlias c in myConfig.Credentials) | ||
{ | ||
if (c.Name == "user1") | ||
{ | ||
Assert.Equal("pass1", c.Pass); | ||
} | ||
else if (c.Name == "user2") | ||
{ | ||
Assert.Equal("pass2", c.Pass); | ||
|
||
namespace Config.Net.Tests.Stores { | ||
public class JsonFileConfigStoreTest : AbstractTestFixture, IDisposable { | ||
private string _path; | ||
private JsonConfigStore _store; | ||
|
||
public JsonFileConfigStoreTest() { | ||
_path = Path.Combine(BuildDir.FullName, "TestData", "sample.json"); | ||
_store = new JsonConfigStore(_path, true); | ||
} | ||
|
||
[Fact] | ||
public void Read_inline_property() { | ||
string key = _store.Read("ApplicationInsights.InstrumentationKey"); | ||
|
||
Assert.NotNull(key); | ||
} | ||
|
||
[Fact] | ||
public void Write_inline_property_reads_back() { | ||
if(!_store.CanWrite) | ||
return; | ||
|
||
string key = "ApplicationInsights.InstrumentationKey"; | ||
|
||
_store.Write(key, "123"); | ||
|
||
Assert.Equal("123", _store.Read(key)); | ||
} | ||
|
||
[Fact] | ||
public void Write_new_value_hierarchically() { | ||
if(!_store.CanWrite) | ||
return; | ||
|
||
string key = "One.Two.Three"; | ||
|
||
_store.Write(key, "111"); | ||
|
||
Assert.Equal("111", _store.Read(key)); | ||
} | ||
|
||
[Fact] | ||
public void AliasesOnCollections() { | ||
IMyConfigUsingAliases myConfig = new ConfigurationBuilder<IMyConfigUsingAliases>() | ||
.UseConfigStore(_store) | ||
.Build(); | ||
|
||
Assert.NotNull(myConfig.Credentials); | ||
foreach(ICredsWithAlias c in myConfig.Credentials) { | ||
if(c.Name == "user1") { | ||
Assert.Equal("pass1", c.Pass); | ||
} else if(c.Name == "user2") { | ||
Assert.Equal("pass2", c.Pass); | ||
} else { | ||
Assert.Equal("user1", c.Name); | ||
} | ||
} | ||
else | ||
{ | ||
Assert.Equal("user1", c.Name); | ||
} | ||
|
||
[Fact] | ||
public void TestCreatingFileInMissingFolder() { | ||
_path = Path.Combine("C:\\temp", "TestData", "sample.json"); | ||
|
||
if(Directory.Exists(_path)) { | ||
Directory.Delete(_path); | ||
} | ||
} | ||
} | ||
|
||
[Fact] | ||
public void TestCreatingFileInMissingFolder() | ||
{ | ||
_path = Path.Combine("C:\\temp", "TestData", "sample.json"); | ||
|
||
if (Directory.Exists(_path)) | ||
{ | ||
Directory.Delete(_path); | ||
} | ||
|
||
string key = "One.Two.Three"; | ||
|
||
_store = new JsonConfigStore(_path, true); | ||
_store.Write(key, "111"); | ||
|
||
Assert.Equal("111", _store.Read(key)); | ||
|
||
Assert.True(File.Exists(_path)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_store.Dispose(); | ||
} | ||
} | ||
public interface ICredsWithAlias | ||
{ | ||
[Option(Alias = "Username")] | ||
string Name { get; set; } | ||
[Option(Alias = "Password")] | ||
string Pass { get; set; } | ||
} | ||
|
||
public interface IMyConfigUsingAliases | ||
{ | ||
[Option(Alias = "Creds")] | ||
IEnumerable<ICredsWithAlias> Credentials { get; } | ||
} | ||
} | ||
|
||
string key = "One.Two.Three"; | ||
|
||
_store = new JsonConfigStore(_path, true); | ||
_store.Write(key, "111"); | ||
|
||
Assert.Equal("111", _store.Read(key)); | ||
|
||
Assert.True(File.Exists(_path)); | ||
} | ||
|
||
public void Dispose() { | ||
_store.Dispose(); | ||
} | ||
} | ||
public interface ICredsWithAlias { | ||
[Option(Alias = "Username")] | ||
string Name { get; set; } | ||
[Option(Alias = "Password")] | ||
string Pass { get; set; } | ||
} | ||
|
||
public interface IMyConfigUsingAliases { | ||
[Option(Alias = "Creds")] | ||
IEnumerable<ICredsWithAlias> Credentials { get; } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.