-
Notifications
You must be signed in to change notification settings - Fork 7
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
4 changed files
with
60 additions
and
22 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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using System; | ||
using System.Globalization; | ||
using NUnit.Framework; | ||
|
||
namespace Fig.Test; | ||
|
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,44 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Fig.Test; | ||
|
||
public class BindingBehavior | ||
{ | ||
[Test] | ||
public void EmptyPathBindsToRoot() | ||
{ | ||
var settings = new SettingsBuilder() | ||
.UseSettingsDictionary(new SettingsDictionary() | ||
{ | ||
{"Hello", "Hi"}, | ||
{"Number", "16"}, | ||
{"OtherNumber", "16"} | ||
}).Build(); | ||
|
||
var settingsWithDefaults = settings.Bind<SettingsWithDefaults>(path:""); | ||
Assert.AreEqual(settingsWithDefaults.Hello, "Hi"); | ||
Assert.AreEqual(settingsWithDefaults.Number, 16); | ||
Assert.AreEqual(settingsWithDefaults.OtherNumber, 16); | ||
|
||
} | ||
|
||
[Test] | ||
public void CanBindToNullableProperties() | ||
{ | ||
//empty dictionary | ||
var settings = new SettingsBuilder().Build(); | ||
var settingsWithDefaults = settings.Bind<SettingsWithDefaults>(); | ||
|
||
Assert.AreEqual(settingsWithDefaults.Hello, "Hello"); | ||
Assert.AreEqual(settingsWithDefaults.Number, 42); | ||
Assert.AreEqual(settingsWithDefaults.OtherNumber, 42); | ||
} | ||
|
||
private class SettingsWithDefaults | ||
{ | ||
public int Number { get; set; } = 42; | ||
public string Hello { get; set; } = nameof(Hello); | ||
|
||
public int? OtherNumber { get; set; } = 42; | ||
} | ||
} |