Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying environment variables in RunSettings file #2128

Merged
merged 5 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Duplicate values in environment variables handled
  • Loading branch information
vagisha-nidhi committed Aug 16, 2019
commit 9bec351dbc29816d32e5e2133092b91cc33e5178
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,10 @@ public static Dictionary<string, string> GetEnvironmentVariables(string runSetti

while (childNodes.MoveNext())
{
environmentVariables.Add(childNodes.Current.Name, childNodes.Current?.Value);
if (!environmentVariables.ContainsKey(childNodes.Current.Name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainsKey [](start = 50, length = 11)

You can use TryAdd, instead of checking and then adding.

{
environmentVariables.Add(childNodes.Current.Name, childNodes.Current?.Value);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,24 @@ public void GetEnvironmentVariablesWithValidValuesInRunSettingsShouldReturnValid
Assert.AreEqual(envVars["RANDOM_PATH2"], @"C:\temp2");
}

[TestMethod]
public void GetEnvironmentVariablesWithDuplicateEnvValuesInRunSettingsShouldReturnValidDictionary()
{
string runSettingsXml = @"<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
<RANDOM_PATH>C:\temp</RANDOM_PATH>
<RANDOM_PATH>C:\temp2</RANDOM_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>";

var envVars = InferRunSettingsHelper.GetEnvironmentVariables(runSettingsXml);

Assert.AreEqual(1, envVars.Count);
Assert.AreEqual(envVars["RANDOM_PATH"], @"C:\temp");
}

[TestMethod]
public void GetEnvironmentVariablesWithEmptyVariablesInRunSettingsShouldReturnEmptyDictionary()
{
Expand Down