Skip to content

Commit

Permalink
Add GetValueDictionaryOrEmpty method to use in sibling libraries for …
Browse files Browse the repository at this point in the history
…capabilities. (#75)

Resolves #15
  • Loading branch information
mialeska authored Jun 4, 2020
1 parent 6ea110f commit ca158e8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ public static IReadOnlyList<T> GetValueListOrEmpty<T>(this ISettingsFile file, s
return file.IsValuePresent(path) ? file.GetValueList<T>(path) : new List<T>();
}

/// <summary>
/// Gets dictionary of values from environment\setting file or empty Dictionary if path doesn't exist in file and environment variables.
/// Exception will not be thrown.
/// Note that each value of dictionary that is present in settings file can be overriden via Environment variable with the same name;
/// (e.g. for capability "safebrowsing.enabled" at dictionary path ".driverSettings.chrome.options" you can set environment variable "driverSettings.chrome.options.safebrowsing.enabled")
/// </summary>
/// <typeparam name="T">Type of a value.</typeparam>
/// <param name="file">Settings file.</param>
/// <param name="path">Path to a value. Depends on file format, it can be xpath, path etc.</param>
/// <returns>Dictionary of values or empty Dictionary.</returns>
public static IReadOnlyDictionary<string, T> GetValueDictionaryOrEmpty<T>(this ISettingsFile file, string path)
{
return file.IsValuePresent(path) ? file.GetValueDictionary<T>(path) : new Dictionary<string, T>();
}

/// <summary>
/// Gets value from environment\setting file or return default of T if path doesn't exist in file and environment variables.
/// Exception will not be threw.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ public void Should_BePossibleTo_GetValueDictionary()
"Dictionary of keys and values was received successively");
}

[Test]
public void Should_BePossibleTo_GetNotEmptyValueDictionary()
{
var expectedDict = new Dictionary<string, object>
{
{"intl.accept_languages", "en"},
{"profile.default_content_settings.popups", "0"},
{"disable-popup-blocking", "true"}
};
Assert.AreEqual(expectedDict,
AddedParamsSettings.GetValueDictionaryOrEmpty<object>(".driverSettings.chrome.options"),
"Dictionary of keys and values was received successively");
}

[Test]
public void Should_BePossibleTo_GetEmptyValueDictionary()
{
var expectedDict = new Dictionary<string, object>();
Assert.AreEqual(expectedDict,
AddedParamsSettings.GetValueDictionaryOrEmpty<object>(".some.absent.path"),
"Dictionary of keys and values was not empty");
}

[Test]
[NonParallelizable]
public void Should_BePossibleTo_OverrideDictionaryOfValues_FromEnvVar()
Expand Down

0 comments on commit ca158e8

Please sign in to comment.