Skip to content

Commit

Permalink
bugfix: ProjectSettings of a SeetingsContainer did not inherit Soluti…
Browse files Browse the repository at this point in the history
…onSettings of that container (#74)
  • Loading branch information
csoltenborn committed Dec 11, 2016
1 parent abfef4e commit 15ccb02
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public void LoadFromXml_UserSettings_AreLoadedCorrectly()

runSettingsContainer.Should().NotBeNull();
runSettingsContainer.SolutionSettings.Should().NotBeNull();
runSettingsContainer.ProjectSettings.Count.Should().Be(0);
runSettingsContainer.ProjectSettings.Count.Should().Be(1);

runSettingsContainer.SolutionSettings.MaxNrOfThreads.Should().Be(3);
runSettingsContainer.ProjectSettings[0].MaxNrOfThreads.Should().Be(4);
runSettingsContainer.SolutionSettings.TraitsRegexesBefore.Should().Be("User");
runSettingsContainer.ProjectSettings[0].TraitsRegexesBefore.Should().Be("User");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.XPath;
Expand Down Expand Up @@ -254,12 +255,12 @@ public void AddRunSettings_ComplexConfiguration_IsMergedCorrectly()
var projectContainer = resultingContainer.GetSettingsForExecutable("project1");
projectContainer.Should().NotBeNull();
projectContainer.AdditionalTestExecutionParam.Should().Be(solutionProject1);
projectContainer.BatchForTestSetup.Should().Be(global);
projectContainer.BatchForTestSetup.Should().Be(userSolution);
projectContainer.BatchForTestTeardown.Should().Be(userProject1);
projectContainer.PathExtension.Should().Be(userProject1);
projectContainer.TestDiscoveryRegex.Should().Be(solutionProject1);
projectContainer.TestDiscoveryRegex.Should().Be(userSolution);
projectContainer.TestNameSeparator.Should().Be(userProject1);
projectContainer.TraitsRegexesAfter.Should().Be(global);
projectContainer.TraitsRegexesAfter.Should().Be(userSolution);
projectContainer.TraitsRegexesBefore.Should().Be(global);
projectContainer.WorkingDir.Should().Be(userProject1);
projectContainer.MaxNrOfThreads.Should().Be(5);
Expand All @@ -271,25 +272,25 @@ public void AddRunSettings_ComplexConfiguration_IsMergedCorrectly()
projectContainer.AdditionalTestExecutionParam.Should().Be(solutionProject2);
projectContainer.BatchForTestSetup.Should().Be(global);
projectContainer.BatchForTestTeardown.Should().Be(solutionProject2);
projectContainer.PathExtension.Should().Be(global);
projectContainer.TestDiscoveryRegex.Should().Be(global);
projectContainer.PathExtension.Should().Be(solutionSolution);
projectContainer.TestDiscoveryRegex.Should().Be(solutionSolution);
projectContainer.TestNameSeparator.Should().Be(solutionProject2);
projectContainer.TraitsRegexesAfter.Should().Be(solutionProject2);
projectContainer.TraitsRegexesBefore.Should().Be(global);
projectContainer.WorkingDir.Should().Be(solutionProject2);
projectContainer.MaxNrOfThreads.Should().Be(0);
projectContainer.MaxNrOfThreads.Should().Be(0);
projectContainer.MaxNrOfThreads.Should().Be(1);
projectContainer.MaxNrOfThreads.Should().Be(1);
projectContainer.NrOfTestRepetitions.Should().Be(3);

projectContainer = resultingContainer.GetSettingsForExecutable("project3");
projectContainer.Should().NotBeNull();
projectContainer.AdditionalTestExecutionParam.Should().Be(userProject3);
projectContainer.BatchForTestSetup.Should().Be(global);
projectContainer.BatchForTestSetup.Should().Be(userSolution);
projectContainer.BatchForTestTeardown.Should().Be(userProject3);
projectContainer.PathExtension.Should().Be(global);
projectContainer.TestDiscoveryRegex.Should().Be(userProject3);
projectContainer.TestNameSeparator.Should().Be(userProject3);
projectContainer.TraitsRegexesAfter.Should().Be(global);
projectContainer.TraitsRegexesAfter.Should().Be(userSolution);
projectContainer.TraitsRegexesBefore.Should().Be(userProject3);
projectContainer.WorkingDir.Should().Be(global);
projectContainer.MaxNrOfThreads.Should().Be(6);
Expand All @@ -315,15 +316,33 @@ private RunSettingsService SetupRunSettingsService(string solutionRunSettingsFil

private void AssertContainsSetting(XmlDocument xml, string nodeName, string value)
{
XmlNodeList list = xml.GetElementsByTagName(nodeName);
list.Count.Should().Be(1);
XmlNode solutionSettingsNode = xml.GetElementsByTagName("SolutionSettings").Item(0);
XmlNodeList list = solutionSettingsNode.SelectNodes($"Settings/{nodeName}");

list.Should().HaveCount(1, $"node {nodeName} should exist only once. XML Document:{Environment.NewLine}{ToFormattedString(xml, 4)}");

XmlNode node = list.Item(0);
node.Should().NotBeNull();
// ReSharper disable once PossibleNullReferenceException
node.InnerText.Should().BeEquivalentTo(value);
}

public static string ToFormattedString(XmlDocument xml, int indentation)
{
string xmlAsString;
using (var sw = new StringWriter())
{
using (var xw = new XmlTextWriter(sw))
{
xw.Formatting = Formatting.Indented;
xw.Indentation = indentation;
xml.WriteContentTo(xw);
}
xmlAsString = sw.ToString();
}
return xmlAsString;
}

private static XPathNavigator EmbedSettingsIntoRunSettings(RunSettingsContainer settingsContainer)
{
var settingsDocument = new XmlDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public RunSettingsContainer(SettingsSerializationContainer serializationContaine
{
_solutionSettings = serializationContainer.SolutionSettings.Settings;
ProjectSettings.AddRange(serializationContainer.SettingsList);
foreach (RunSettings projectSettings in ProjectSettings)
{
projectSettings.GetUnsetValuesFrom(_solutionSettings);
}
}

public RunSettings GetSettingsForExecutable(string executable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
</Settings>
</SolutionSettings>
<ProjectSettings>
<Settings ProjectRegex="LoadTests_gta\.exe|CrashingTests_gta\.exe">
<MaxNrOfThreads>4</MaxNrOfThreads>
</Settings>
</ProjectSettings>
</GoogleTestAdapterSettings>
</RunSettings>

0 comments on commit 15ccb02

Please sign in to comment.