< Summary - Helper.Tests

Information
Class: Configuration.Helper.SettingsSection
Assembly: Configuration.Helper
File(s): D:\a\NuGetPackages\NuGetPackages\src\Helper\Configuration.Helper\SettingsStore\SettingsSection.cs
Tag: 3_8508158812
Line coverage
100%
Covered lines: 18
Uncovered lines: 0
Coverable lines: 18
Total lines: 60
Line coverage: 100%
Branch coverage
87%
Covered branches: 7
Total branches: 8
Branch coverage: 87.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Settings()100%11100%
.ctor(...)100%11100%
AddSetting(...)100%44100%
GetSetting(...)75%44100%

File(s)

D:\a\NuGetPackages\NuGetPackages\src\Helper\Configuration.Helper\SettingsStore\SettingsSection.cs

#LineLine coverage
 1namespace Configuration.Helper;
 2
 3/// <summary>Class to contain the settings from a configuration file section.</summary>
 4public class SettingsSection : ISettingsSection
 5{
 6  #region Properties
 7
 8  /// <inheritdoc />
 2069  public IDictionary<string, string> Settings { get; }
 10
 11  #endregion
 12
 13  #region Constructor
 14
 15  /// <summary>Constructor using a string comparer.</summary>
 16  /// <param name="comparer">Comparer to use for the key/value collection.</param>
 10117  internal SettingsSection( StringComparer comparer )
 10118  {
 10119    Settings = new SortedDictionary<string, string>( comparer );
 10120  }
 21
 22  #endregion
 23
 24  #region Internal Methods
 25
 26  /// <summary>Adds or updates a setting in the key/value collection.</summary>
 27  /// <param name="key">Key of the setting.</param>
 28  /// <param name="value">Value of the setting.</param>
 29  /// <returns>True if the setting has been added or updated.</returns>
 30  internal bool AddSetting( string key, string value )
 9631  {
 32    // Check the required parameters are supplied
 9833    if( string.IsNullOrWhiteSpace( key ) ) { return false; }
 34
 35    // Update or add the setting
 9536    key = key.Trim();
 9537    value = value.Trim();
 9838    if( Settings.ContainsKey( key ) ) { Settings[key] = value; }
 28239    else { Settings.Add( key, value ); }
 40
 9541    return true;
 9642  }
 43
 44  #endregion
 45
 46  #region Public Methods
 47
 48  /// <inheritdoc />
 49  public string GetSetting( string settingKey )
 850  {
 51    // Check the required parameter is supplied
 852    if( string.IsNullOrWhiteSpace( settingKey ) ) { return string.Empty; }
 853    settingKey = settingKey.Trim();
 54
 55    // Return the setting value
 856    return Settings.ContainsKey( settingKey ) ? Settings[settingKey] : string.Empty;
 857  }
 58
 59  #endregion
 60}