Skip to content

Commit

Permalink
Review : remove unnecessary method ExtractDirectives
Browse files Browse the repository at this point in the history
... and useless test
  • Loading branch information
Thibaud DESODT authored and tsimbalar committed Nov 8, 2017
1 parent 1c3449c commit f732324
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
15 changes: 4 additions & 11 deletions src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public KeyValuePairSettings(IReadOnlyDictionary<string, string> settings)
public void Configure(LoggerConfiguration loggerConfiguration)
{
if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration));

var directives = ExtractDirectives(_settings);

var directives = _settings
.Where(kvp => _supportedDirectives.Any(kvp.Key.StartsWith))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

var declaredLevelSwitches = ParseNamedLevelSwitchDeclarationDirectives(directives);

Expand Down Expand Up @@ -161,15 +163,6 @@ where matchCallables.IsMatch(wt.Key)
}
}

internal static IReadOnlyDictionary<string, string> ExtractDirectives(IReadOnlyDictionary<string, string> settings)
{
var directives = settings
.Where(kvp => _supportedDirectives.Any(kvp.Key.StartsWith))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

return new ReadOnlyDictionary<string, string>(directives);
}

internal static bool IsValidSwitchName(string input)
{
return Regex.IsMatch(input, LevelSwitchNameRegex);
Expand Down
16 changes: 1 addition & 15 deletions test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,7 @@ public void DuplicateKeysCauseArgumentException()
var ex = Assert.ThrowsAny<ArgumentException>(action);
Assert.NotNull(ex);
Assert.Contains("An item with the same key has already been added.", ex.Message);
}

[Fact]
public void IrrelevantKeysAreIgnored()
{
var irrelevantSettings = new Dictionary<string, string>()
{
["whatever:foo:bar"] = "willBeIgnored",
["irrelevant"] = "willBeIgnored",
};

var directives = KeyValuePairSettings.ExtractDirectives(irrelevantSettings);

Assert.False(directives.Any());
}
}

[Fact]
public void FindsConfigurationAssemblies()
Expand Down

0 comments on commit f732324

Please sign in to comment.