예제 #1
0
        private TestSettingsNodes ReadTestSettingsNodes(string testSettingsPath)
        {
            var testSettingsNodes = new TestSettingsNodes();

            using (XmlTextReader reader = new XmlTextReader(testSettingsPath))
            {
                reader.Namespaces = false;

                var testSettingsXmlDoc = new XmlDocument();
                testSettingsXmlDoc.Load(reader);
                var testSettingsRoot = testSettingsXmlDoc.DocumentElement;

                // Select the interesting nodes from the xml.
                testSettingsNodes.Deployment     = testSettingsRoot.SelectSingleNode(@"/TestSettings/Deployment");
                testSettingsNodes.Script         = testSettingsRoot.SelectSingleNode(@"/TestSettings/Scripts");
                testSettingsNodes.WebSettings    = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution/TestTypeSpecific/WebTestRunConfiguration");
                testSettingsNodes.Datacollectors = testSettingsRoot.SelectNodes(@"/TestSettings/Execution/AgentRule/DataCollectors/DataCollector");
                testSettingsNodes.Timeout        = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution/Timeouts");
                testSettingsNodes.UnitTestConfig = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution/TestTypeSpecific/UnitTestRunConfig");
                testSettingsNodes.Hosts          = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution/Hosts");
                testSettingsNodes.Execution      = testSettingsRoot.SelectSingleNode(@"/TestSettings/Execution");

                if (testSettingsNodes.Timeout != null && (testSettingsNodes.Timeout.Attributes[AgentNotRespondingTimeoutAttribute] != null ||
                                                          testSettingsNodes.Timeout.Attributes[DeploymentTimeoutAttribute] != null || testSettingsNodes.Timeout.Attributes[ScriptTimeoutAttribute] != null))
                {
                    Console.WriteLine(string.Format(CultureInfo.CurrentCulture, CommandLineResources.UnsupportedAttributes));
                }
            }

            return(testSettingsNodes);
        }
예제 #2
0
        /// <summary>
        /// Adds the legacy nodes to runSettings xml.
        /// </summary>
        /// <param name="testSettingsNodes">testSettingsNodes</param>
        /// <param name="testTimeout">testTimeout</param>
        /// <param name="parallelTestCount">parallelTestCount</param>
        /// <param name="hostProcessPlatform">hostProcessPlatform</param>
        /// <param name="newXmlDoc">newXmlDoc</param>
        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);
        }