private void RemoveAssociatedUnitTestNodes(XmlDocument xmlDoc, List <XmlNode> lstRemovedUnitTestResult) { var lstUnitTestResultIdentifier = lstRemovedUnitTestResult.Select(x => GetUnitTestResultNodeIdentifier(x)).ToList(); NodeNames nodeNameExecution = NodeNames.Execution; string strNodeNameExecutionParent = nodeNameExecution.GetParentNodeName().ToString(); var nodes = xmlDoc.GetElementsByTagName(nodeNameExecution.ToString()); var parentNode = xmlDoc.GetElementsByTagName(NodeNames.UnitTest.GetParentNodeName().ToString())[0]; var lstNodes = new List <XmlNode>(Shim <XmlNode>(nodes)); foreach (XmlNode xmlNodeExecution in lstNodes) { if (xmlNodeExecution.ParentNode.Name == strNodeNameExecutionParent) { string strId = GetExecutionNodeIdentifier(xmlNodeExecution); int index = lstUnitTestResultIdentifier.IndexOf(strId); if (index >= 0) { lstUnitTestResultIdentifier.RemoveAt(index); parentNode.RemoveChild(xmlNodeExecution.ParentNode); } } } }
public void CreateXmlOfTestCasesWithGivenOutcomes(string strResultFile, string strXmlToContainTestCasesWithGivenOutcomes, IEnumerable <string> outcomes) { StringBuilder sbTestCasesXml = new StringBuilder("<?xml version='1.0' encoding='utf-8' ?>"); sbTestCasesXml.AppendLine("<TestCases>"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(strResultFile); NodeNames nodeNameExecution = NodeNames.Execution; var executionNodes = xmlDoc.GetElementsByTagName(nodeNameExecution.ToString()); string strNodeNameExecutionParent = nodeNameExecution.GetParentNodeName().ToString(); List <string> lstTestCases = new List <string>(); var unitTestResultNodes = Shim <XmlNode>(xmlDoc.GetElementsByTagName(NodeNames.UnitTestResult.ToString())); Parallel.ForEach(unitTestResultNodes, (unitTestResultNode) => { if (outcomes.Contains(GetTestCaseOutcome(unitTestResultNode).ToString().ToLower())) { string strUnitTestResultNodeId = GetUnitTestResultNodeIdentifier(unitTestResultNode); foreach (XmlNode xmlNodeExecution in executionNodes) { if (xmlNodeExecution.ParentNode.Name == strNodeNameExecutionParent) { string strExecutionNodeId = GetExecutionNodeIdentifier(xmlNodeExecution); if (strUnitTestResultNodeId == strExecutionNodeId) { var testMethodNode = Shim <XmlNode>(xmlNodeExecution.ParentNode.ChildNodes) .Where(x => x.Name == NodeNames.TestMethod.ToString()).First(); lock (lstTestCases) { lstTestCases.Add(testMethodNode.GetAttributeValue(TestMethodAttributes.className.ToString()).Split(',').First() + "." + testMethodNode.GetAttributeValue(TestMethodAttributes.name.ToString())); } break; } } } } }); foreach (string strTestCase in lstTestCases) { sbTestCasesXml.AppendLine(string.Format("<TestCase Name='{0}'></TestCase>", strTestCase)); } sbTestCasesXml.AppendLine("</TestCases>"); XmlDocument xmlDocToContainTestCasesWithGivenOutcomes = new XmlDocument(); xmlDocToContainTestCasesWithGivenOutcomes.LoadXml(sbTestCasesXml.ToString()); xmlDocToContainTestCasesWithGivenOutcomes.Save(strXmlToContainTestCasesWithGivenOutcomes); }
private List <XmlNode> RemoveDuplicateNodes(XmlDocument xmlDoc, NodeNames nodeName, string strAttributeToBeCheckedToMarkAsDuplicate, Func <IEnumerable <XmlNode>, IEnumerable <XmlNode> > processorBeforeRemoving = null) { var nodes = Shim <XmlNode>(xmlDoc.GetElementsByTagName(nodeName.ToString())) .Where(x => x.ParentNode.Name == nodeName.GetParentNodeName().ToString()); var parentNode = xmlDoc.GetElementsByTagName(nodeName.GetParentNodeName().ToString())[0]; Dictionary <string, List <XmlNode> > dicNodesByAttributeValue = new Dictionary <string, List <XmlNode> >(); foreach (XmlNode xmlNode in nodes) { string strAttributeValue = xmlNode.GetAttributeValue(strAttributeToBeCheckedToMarkAsDuplicate); if (!dicNodesByAttributeValue.ContainsKey(strAttributeValue)) { dicNodesByAttributeValue.Add(strAttributeValue, new List <XmlNode>()); } dicNodesByAttributeValue[strAttributeValue].Add(xmlNode); } List <XmlNode> lstRemovedNodes = new List <XmlNode>(); foreach (var keyValPair in dicNodesByAttributeValue) { IEnumerable <XmlNode> nodesToBeRemoved = keyValPair.Value; if (processorBeforeRemoving != null) { nodesToBeRemoved = processorBeforeRemoving(nodesToBeRemoved).ToList(); } for (int i = 1; i < nodesToBeRemoved.Count(); i++) { lstRemovedNodes.Add(nodesToBeRemoved.ElementAt(i)); parentNode.RemoveChild(nodesToBeRemoved.ElementAt(i)); } } return(lstRemovedNodes); }
private void ConsolidateNodes(XmlDocument xmlDocConsolidatedReport, XmlDocument xmlDocReportToBeMerged, NodeNames nodeName) { string strNodeName = nodeName.ToString(); string strParentNodeName = nodeName.GetParentNodeName().ToString(); var nodesOfReportToBeMerged = Shim <XmlNode>(xmlDocReportToBeMerged.GetElementsByTagName(strNodeName)) .Where(x => x.ParentNode.Name == strParentNodeName); var parentNodeOfGivenNodeInConsolidatedReport = xmlDocConsolidatedReport.GetElementsByTagName(strParentNodeName)[0]; foreach (XmlNode xmlNode in nodesOfReportToBeMerged) { parentNodeOfGivenNodeInConsolidatedReport.AppendChild(xmlDocConsolidatedReport.ImportNode(xmlNode, true)); } }