-
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.
* Base path was not set causing an NPR * improve env var and command line handling * Add sections to docs
- Loading branch information
Showing
10 changed files
with
228 additions
and
19 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
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,50 @@ | ||
using System; | ||
using NUnit.Framework; | ||
|
||
namespace Fig.Test | ||
{ | ||
public class BuilderTests | ||
{ | ||
[Test] | ||
public void CanLoadRequiredFile() | ||
{ | ||
var settings = new SettingsBuilder() | ||
.UseAppSettingsJson("appsettings.json", required: true) | ||
.Build(); | ||
Assert.DoesNotThrow(() => settings.Get("AllowedHosts")); | ||
} | ||
|
||
[Test] | ||
public void CanLoadRequiredFileWithVariableExpansion() | ||
{ | ||
Environment.SetEnvironmentVariable("ENV", "TEST"); | ||
var settings = new SettingsBuilder() | ||
.UseEnvironmentVariables() | ||
.UseAppSettingsJson("appsettings.${ENV}.json", required: true) | ||
.Build(); | ||
Assert.DoesNotThrow(() => settings.Get("AllowedHosts")); | ||
} | ||
|
||
[Test] | ||
public void CanReferenceOptionalNonExistentFile() | ||
{ | ||
Assert.DoesNotThrow(() => | ||
{ | ||
var settings = new SettingsBuilder() | ||
.UseAppSettingsJson("nonexistent.json", required: false) | ||
.Build(); | ||
}); | ||
} | ||
|
||
[Test] | ||
public void CanReferenceOptionalNonExistentFileWithVariableExpansion() | ||
{ | ||
Assert.DoesNotThrow(() => | ||
{ | ||
var settings = new SettingsBuilder() | ||
.UseAppSettingsJson("nonexistent.${ENV}.json", required: false) | ||
.Build(); | ||
}); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using NUnit.Framework; | ||
|
||
namespace Fig.Test | ||
{ | ||
public class CommandLineArgsTests | ||
{ | ||
[Test] | ||
public void WithPrefix() | ||
{ | ||
var args = new[] {"--fig:Color=red", "--fig:Size=4", "other=20"}; | ||
var settings = new SettingsBuilder().UseCommandLine(args).Build(); | ||
var colorExists = settings.SettingsDictionary.TryGetValue("Color", "", out _); | ||
var sizeExists = settings.SettingsDictionary.TryGetValue("Size", "", out _); | ||
var prefixlessNotPresent = settings.SettingsDictionary.TryGetValue("Other", "", out _); | ||
|
||
Assert.True(colorExists); | ||
Assert.True(sizeExists); | ||
Assert.False(prefixlessNotPresent); | ||
} | ||
|
||
[Test] | ||
public void WithoutPrefix() | ||
{ | ||
var args = new[] {"myApp.Color=red", "Size=4", "--other=20"}; | ||
var settings = new SettingsBuilder().UseCommandLine(args, prefix:"").Build(); | ||
var colorExists = settings.SettingsDictionary.TryGetValue("myApp.Color", "", out _); | ||
var sizeExists = settings.SettingsDictionary.TryGetValue("Size", "", out _); | ||
var nonMatchingKey = settings.SettingsDictionary.TryGetValue("--Other", "", out _); | ||
|
||
Assert.True(colorExists); | ||
Assert.True(sizeExists); | ||
Assert.False(nonMatchingKey); | ||
} | ||
} | ||
} |
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,35 @@ | ||
using System.Collections.Generic; | ||
using Fig.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Fig.Test | ||
{ | ||
public class EnvironmentVarsSourceTests | ||
{ | ||
[Test] | ||
public void WithDroppedPrefix() | ||
{ | ||
var dictionary = new Dictionary<string, string>() | ||
{ | ||
["FIG_A"] = "fig.a", | ||
|
||
}; | ||
var source = new EnvironmentVarsSettingsSource(dictionary, "FIG_", dropPrefix: true); | ||
var settings = source.ToSettingsDictionary(); | ||
Assert.True(settings.ContainsKey("a")); | ||
} | ||
|
||
[Test] | ||
public void WithRetainedPrefix() | ||
{ | ||
var dictionary = new Dictionary<string, string>() | ||
{ | ||
["FIG_A"] = "fig.a", | ||
|
||
}; | ||
var source = new EnvironmentVarsSettingsSource(dictionary, "FIG_", dropPrefix: false); | ||
var settings = source.ToSettingsDictionary(); | ||
Assert.True(settings.ContainsKey("fig.a")); | ||
} | ||
} | ||
} |
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,26 @@ | ||
{ | ||
"Timeout" : 42, | ||
"ConnectionStrings": { | ||
"DefaultConnection": "DataSource=app.db" | ||
}, | ||
"Servers" : ["10.0.0.1", "10.0.0.2"], | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*", | ||
"Simpsons" : [ | ||
{ "Name" : "Bart", "Age" : 12}, | ||
{ "Name" : "Homer", "Age" : 35} | ||
], | ||
|
||
"EnvQualified:PROD" : { | ||
"a" : 1, | ||
"b" : 1 | ||
}, | ||
"EnvQualified:TEST" : { | ||
"a" : 2, | ||
"b" : 2 | ||
} | ||
} |
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,4 +1,4 @@ | ||
version: 1.7.{build} | ||
version: 1.8.{build} | ||
image: Ubuntu1804 | ||
assembly_info: | ||
patch: true | ||
|