Skip to content

Commit

Permalink
Changes to allow special characters in parameter names (#2481)
Browse files Browse the repository at this point in the history
Allow separators on parameter names.
  • Loading branch information
cvpoienaru authored Sep 1, 2020
1 parent 2f27b25 commit 327c428
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void UpdateRunSettingsNode(this IRunSettingsProvider runSettingsPr
/// <returns></returns>
public static Match GetTestRunParameterNodeMatch(this IRunSettingsProvider runSettingsProvider, string node)
{
var attrName = $"(?<{AttributeNameString}>\\w+)";
var attrName = $"(?<{AttributeNameString}>[\\w.:-]+)";
var attrValue = $"(?<{AttributeValueString}>.+)";
Regex regex = new Regex($"{Constants.TestRunParametersName}.{ParameterString}\\(name\\s*=\\s*\"{attrName}\"\\s*,\\s*value\\s*=\\s*\"{attrValue}\"\\)");
Match match = regex.Match(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,7 @@ public void UpdateRunSettingsNodeShouldAddNewKeyIfNotPresent()
[TestMethod]
public void UpdateTestRunParameterSettingsNodeShouldAddNewKeyIfNotPresent()
{
var match = this.runSettingsProvider.GetTestRunParameterNodeMatch("TestRunParameters.Parameter(name=\"weburl\",value=\"http://localhost//abc\")");
var runSettingsWithTestRunParameters = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<RunSettings>\r\n <TestRunParameters>\r\n <Parameter name=\"weburl\" value=\"http://localhost//abc\" />\r\n </TestRunParameters>\r\n</RunSettings>";

this.runSettingsProvider.UpdateRunSettings("<RunSettings>\r\n </RunSettings>");
this.runSettingsProvider.UpdateTestRunParameterSettingsNode(match);

Assert.AreEqual(runSettingsWithTestRunParameters, this.runSettingsProvider.ActiveRunSettings.SettingsXml);
this.CheckRunSettingsAreUpdated("weburl", @"http://localhost//abc");
}

[TestMethod]
Expand All @@ -156,6 +150,24 @@ public void UpdateTetsRunParameterSettingsNodeShouldOverrideValueIfKeyIsAlreadyP
Assert.AreEqual(runSettingsWithTestRunParametersOverrode, this.runSettingsProvider.ActiveRunSettings.SettingsXml);
}

[TestMethod]
public void TestRunParameterSettingsNodeCanContainSpecialCharacters()
{
this.CheckRunSettingsAreUpdated("weburl:name", @"http://localhost//abc");
}

[TestMethod]
public void TestRunParameterSettingsNodeCanBeJustASingleCharacter()
{
this.CheckRunSettingsAreUpdated("a", @"http://localhost//abc");
}

[TestMethod]
public void TestRunParameterSettingsNodeCanMixSpecialCharacters()
{
this.CheckRunSettingsAreUpdated("___this_Should:be-valid.2", @"http://localhost//abc");
}

[TestMethod]
public void UpdateRunSettingsNodeShouldUpdateKeyIfAlreadyPresent()
{
Expand Down Expand Up @@ -230,6 +242,25 @@ public void QueryRunSettingsNodeShouldReturnCorrectValue()
Assert.AreEqual("x86", this.runSettingsProvider.QueryRunSettingsNode("RunConfiguration.TargetPlatform"));
}

private void CheckRunSettingsAreUpdated(string parameterName, string parameterValue)
{
var match = this.runSettingsProvider.GetTestRunParameterNodeMatch(
$@"TestRunParameters.Parameter(name=""{parameterName}"",value=""{parameterValue}"")");
var runSettingsWithTestRunParameters = string.Join(
Environment.NewLine,
$@"<?xml version=""1.0"" encoding=""utf-16""?>",
$@"<RunSettings>",
$@" <TestRunParameters>",
$@" <Parameter name=""{parameterName}"" value=""{parameterValue}"" />",
$@" </TestRunParameters>",
$@"</RunSettings>");

this.runSettingsProvider.UpdateRunSettings("<RunSettings>\r\n </RunSettings>");
this.runSettingsProvider.UpdateTestRunParameterSettingsNode(match);

Assert.AreEqual(runSettingsWithTestRunParameters, this.runSettingsProvider.ActiveRunSettings.SettingsXml);
}

private class TestableRunSettingsProvider : IRunSettingsProvider
{
public RunSettings ActiveRunSettings
Expand Down

0 comments on commit 327c428

Please sign in to comment.