in src/SettingsMigrator/Migrator.cs [253:345]
private void AddLegacyNodes(TestSettingsNodes testSettingsNodes, string testTimeout, string parallelTestCount, string hostProcessPlatform, XmlDocument newXmlDoc)
{
if (testSettingsNodes.Deployment == null && testSettingsNodes.Script == null && testSettingsNodes.UnitTestConfig == null &&
string.IsNullOrEmpty(parallelTestCount) && string.IsNullOrEmpty(testTimeout) && string.IsNullOrEmpty(hostProcessPlatform) && testSettingsNodes.Hosts == null)
{
return;
}
// Add ForcedLegacy node.
var mstestNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest");
XmlNode forcedLegacyNode;
if (mstestNode == null)
{
mstestNode = newXmlDoc.CreateNode(XmlNodeType.Element, MSTestNodeName, null);
newXmlDoc.DocumentElement.AppendChild(mstestNode);
mstestNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest");
}
forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode");
if (forcedLegacyNode == null)
{
forcedLegacyNode = newXmlDoc.CreateNode(XmlNodeType.Element, ForcedLegacyModeName, null);
mstestNode.AppendChild(newXmlDoc.ImportNode(forcedLegacyNode, deep: true));
forcedLegacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/MSTest/ForcedLegacyMode");
}
forcedLegacyNode.InnerText = "true";
// Remove if the legacy node already exists.
var legacyNode = newXmlDoc.DocumentElement.SelectSingleNode(@"/RunSettings/LegacySettings");
if (legacyNode != null)
{
Console.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.IgnoringLegacySettings));
legacyNode.ParentNode.RemoveChild(legacyNode);
}
legacyNode = newXmlDoc.CreateNode(XmlNodeType.Element, LegacySettingsNodeName, null);
if (testSettingsNodes.Deployment != null)
{
legacyNode.AppendChild(newXmlDoc.ImportNode(testSettingsNodes.Deployment, deep: true));
}
if (testSettingsNodes.Script != null)
{
legacyNode.AppendChild(newXmlDoc.ImportNode(testSettingsNodes.Script, deep: true));
}
// Execution node.
if (testSettingsNodes.UnitTestConfig != null || !string.IsNullOrEmpty(parallelTestCount) || !string.IsNullOrEmpty(testTimeout) || testSettingsNodes.Hosts != null)
{
var newExecutionNode = newXmlDoc.CreateNode(XmlNodeType.Element, ExecutionNodeName, null);
if (!string.IsNullOrEmpty(parallelTestCount))
{
var paralellAttribute = newXmlDoc.CreateAttribute(ParallelTestCountAttributeName);
paralellAttribute.Value = parallelTestCount;
newExecutionNode.Attributes.Append(paralellAttribute);
}
if (!string.IsNullOrEmpty(hostProcessPlatform))
{
var hostProcessPlatformAttribute = newXmlDoc.CreateAttribute(HostProcessPlatformAttributeName);
hostProcessPlatformAttribute.Value = hostProcessPlatform;
newExecutionNode.Attributes.Append(hostProcessPlatformAttribute);
}
if (!string.IsNullOrEmpty(testTimeout))
{
var newTimeoutsNode = newXmlDoc.CreateNode(XmlNodeType.Element, TimeoutsNodeName, null);
var testtimeoutattribute = newXmlDoc.CreateAttribute(TestTimeoutAttributeName);
testtimeoutattribute.Value = testTimeout;
newTimeoutsNode.Attributes.Append(testtimeoutattribute);
newExecutionNode.AppendChild(newXmlDoc.ImportNode(newTimeoutsNode, deep: true));
}
if (testSettingsNodes.Hosts != null)
{
newExecutionNode.AppendChild(newXmlDoc.ImportNode(testSettingsNodes.Hosts, deep: true));
}
if (testSettingsNodes.UnitTestConfig != null)
{
var testTypeSpecificNode = newXmlDoc.CreateNode(XmlNodeType.Element, TestTypeSpecificNodeName, null);
testTypeSpecificNode.AppendChild(newXmlDoc.ImportNode(testSettingsNodes.UnitTestConfig, deep: true));
newExecutionNode.AppendChild(newXmlDoc.ImportNode(testTypeSpecificNode, deep: true));
}
legacyNode.AppendChild(newXmlDoc.ImportNode(newExecutionNode, deep: true));
}
newXmlDoc.DocumentElement.AppendChild(legacyNode);
}