public void OnceUponALovelyDayWhenAttemptingToInvokeTryGetConnectionStringIWasExpectingTheKeyToNotBeFound() { IConnectionStringProvider provider = new XpathConnectionStringProvider(CONFIGURATION_FILE, "Thou shall not find the key!"); bool result = provider.TryGetConnectionString(out string outConnection); Assert.False(result, "The connection string should not be found."); Assert.Null(outConnection); }
public void TryGetConnectionString_FileNotFound() { IConnectionStringProvider provider = new XpathConnectionStringProvider(CONFIGURATION_FILE + "Thou shall not find the file!", "/configuration/applicationSettings/nPVR.Services.AAAAClient.Properties.Settings/setting[@name=\"AAAAEndpoint\"]/value"); bool result = provider.TryGetConnectionString(out string outConnection); Assert.False(result, "The file should not be found."); Assert.Null(outConnection); }
public void TryGetConnectionString() { IConnectionStringProvider provider = new XpathConnectionStringProvider(CONFIGURATION_FILE, "/configuration/applicationSettings/nPVR.Services.AAAAClient.Properties.Settings/setting[@name=\"AAAAEndpoint\"]/value"); bool result = provider.TryGetConnectionString(out string outConnection); Assert.True(result, "The connection string was not found!"); Assert.Equal("http://localhost/service/api/v1/", outConnection); }
private static IConnectionStringProvider ParseConnectionStringProvider(JsonNode node, IFilePathMapper pathMapper) { if (node.AsObject == null) { return(new StaticConnectionStringProvider(node.Value)); } JsonClass objClass = node.AsObject; SupportedConnectionStringLocators locator; if (!Enum.TryParse(node["locator"]?.Value, out locator)) { throw new NAMEException($"The locator {node["locator"]?.Value} is not supported."); } IConnectionStringProvider provider = null; string key; switch (locator) { #if NET45 case SupportedConnectionStringLocators.ConnectionStrings: key = node["key"]?.Value; provider = new ConnectionStringsConnectionStringProvider(key); break; case SupportedConnectionStringLocators.AppSettings: key = node["key"]?.Value; provider = new AppSettingsConnectionStringProvider(key); break; case SupportedConnectionStringLocators.VSSettingsFile: key = node["key"]?.Value; string section = node["section"]?.Value; if (string.IsNullOrEmpty(section)) { throw new ArgumentNullException("section", "The section must be specified."); } provider = new VisualStudioSetingsFileConnectionStringProvider(section, key); break; #endif case SupportedConnectionStringLocators.JSONPath: { key = node["expression"]?.Value; string file = node["file"]?.Value; if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("file", "The file must be specified."); } provider = new JsonPathConnectionStringProvider(pathMapper.MapPath(file), key); } break; case SupportedConnectionStringLocators.XPath: { key = node["expression"]?.Value; string file = node["file"]?.Value; if (string.IsNullOrEmpty(file)) { throw new ArgumentNullException("file", "The file must be specified."); } provider = new XpathConnectionStringProvider(pathMapper.MapPath(file), key); } break; default: throw new NAMEException($"The locator {locator.ToString()} is not supported.."); } if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException($"The connection string key/expression must be specified."); } return(provider); }