public TestReportComponentBody GetByName(string testName) { if (string.IsNullOrEmpty(testName)) { throw new ArgumentNullException("testName"); } var testReportItem = new TestReportComponentBody(); try { xmlDocument.Load(Directory); testReportItem = (from node in xmlDocument.DocumentElement.ChildNodes.Cast <XmlNode>() where node.Name == "TestReportItem" && node.SelectSingleNode("Title").InnerText == testName select GetTesteportItem(node)).First(); } catch (XmlException ex) { Debug.WriteLine(string.Format("XmlException for test name: {0}", ex.Message)); testReportItem = new TestReportComponentBody() { Title = $"Error - { testName } something went wrong trying to read this object in the test report" }; } return(testReportItem); }
internal void WriteReportItemToDocument(TestReportComponentBody testreportItem) { foreach (var item in testreportItem.ListOfComponents) { var operation = writeOperations[item.TypeOfComponent]; operation(item); } ; }
public TestReportComponentBody GetTesteportItem(XmlNode node) { try { var nodeAttribute = node.Attributes["type"].Value; var componentType = Enum.TryParse(nodeAttribute, out TestreportComponentType reportItemType) ? reportItemType : TestreportComponentType.Null; if (componentType == TestreportComponentType.Body) { var testReportBody = new TestReportComponentBody(); var nodeType = node.Attributes["type"].Value; var reportType = Enum.TryParse(nodeType, out TestreportComponentType bodyType) ? bodyType : TestreportComponentType.Null; foreach (XmlNode childNode in node.ChildNodes) { if (componentType == TestreportComponentType.Body) { return(GetTesteportItem(childNode)); } ; ITestReportComponent reportComponent = TestReportComponentFactory.GetComponentFromXmlNode(childNode); ITestReportComponent intailisedTestReportComponent = PopulateTestreportComponent.ParseXmlNode(childNode, ref reportComponent); testReportBody.ListOfComponents.Add(intailisedTestReportComponent); } } return(new TestReportComponentBody() { Title = $"Error - something went wrong trying to read this object in the test report" }); } catch (XmlException ex) { Debug.WriteLine(string.Format("XmlException for test name: {0}", ex.Message)); throw ex; } }