From f7323243d273b847e8d4a93bf83b808d0a9fc2d5 Mon Sep 17 00:00:00 2001 From: Thibaud DESODT Date: Tue, 24 Oct 2017 07:07:14 +0200 Subject: [PATCH] Review : remove unnecessary method ExtractDirectives ... and useless test --- .../KeyValuePairs/KeyValuePairSettings.cs | 15 ++++----------- .../Settings/KeyValuePairSettingsTests.cs | 16 +--------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs index 51bbcb1d1..3870b5dea 100644 --- a/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs +++ b/src/Serilog/Settings/KeyValuePairs/KeyValuePairSettings.cs @@ -83,8 +83,10 @@ public KeyValuePairSettings(IReadOnlyDictionary 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); @@ -161,15 +163,6 @@ where matchCallables.IsMatch(wt.Key) } } - internal static IReadOnlyDictionary ExtractDirectives(IReadOnlyDictionary settings) - { - var directives = settings - .Where(kvp => _supportedDirectives.Any(kvp.Key.StartsWith)) - .ToDictionary(kvp => kvp.Key, kvp => kvp.Value); - - return new ReadOnlyDictionary(directives); - } - internal static bool IsValidSwitchName(string input) { return Regex.IsMatch(input, LevelSwitchNameRegex); diff --git a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs index 405a13a29..a16bae19c 100644 --- a/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs +++ b/test/Serilog.Tests/Settings/KeyValuePairSettingsTests.cs @@ -28,21 +28,7 @@ public void DuplicateKeysCauseArgumentException() var ex = Assert.ThrowsAny(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() - { - ["whatever:foo:bar"] = "willBeIgnored", - ["irrelevant"] = "willBeIgnored", - }; - - var directives = KeyValuePairSettings.ExtractDirectives(irrelevantSettings); - - Assert.False(directives.Any()); - } + } [Fact] public void FindsConfigurationAssemblies()