Example #1
0
        public TestReportItem GetByName(string testName)
        {
            if (string.IsNullOrEmpty(testName))
            {
                throw new ArgumentNullException("testName");
            }

            var testReportItem = new TestReportItem();

            int depth = 0;

            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Directory);

                testReportItem = (from node in xmlDoc.DocumentElement.ChildNodes.Cast <XmlNode>()
                                  where node.Name == "TestReportItem" && node.SelectSingleNode("Title").InnerText == testName
                                  select ParseXmlNodeToTestReportItem(node, ref depth)).First();
            }
            catch (XmlException ex)
            {
                Debug.WriteLine(string.Format("XmlException for test name: {0}", ex.Message));

                testReportItem = new TestReportItem()
                {
                    Title = $"Error - { testName } something went wrong trying to read this object in the test report"
                };
            }

            return(testReportItem);
        }
Example #2
0
        /// <summary>
        /// Parses an XmlNode to TestReportItem object
        /// </summary>
        /// <param name="node">An XmlNode object</param>
        /// <returns>TestReportItem object</returns>
        private TestReportItem ParseXmlNodeToTestReportItem(XmlNode node, ref int recursiveDepth)
        {
            List <string> childNodes;

            TestReportItem testReportItem;

            int depth = recursiveDepth++;

            Debug.WriteLine(depth);

            try
            {
                if (node.ChildNodes.Count < 1)
                {
                    return(null);
                }
                childNodes = node.ChildNodes.Cast <XmlNode>().Select(n => n.Name).ToList();
                bool titleNodeExists      = childNodes.Contains("Title");
                bool subtitleNodeExists   = childNodes.Contains("SubTitle");
                bool tableTitleNodeExists = childNodes.Contains("TableTitles");
                bool furtherInfoExists    = childNodes.Contains("FurtherInfo");
                bool referenceExists      = childNodes.Contains("Reference");
                bool testStandardsExist   = childNodes.Contains("TestStandards");
                TestReportItemType typeOfTestReportItem = node.Name == "TestReportTestStandard" ? TestReportItemType.TestStandard : node.Name == "TestReportProductStandard" ? TestReportItemType.ProductStandard : TestReportItemType.Null;

                testReportItem = new TestReportItem()
                {
                    Title                    = titleNodeExists ? node.SelectSingleNode("Title").InnerText : string.Empty,
                    SubTitle                 = subtitleNodeExists ? node.SelectSingleNode("SubTitle").InnerText : string.Empty,
                    TableTitles              = tableTitleNodeExists ? node.SelectSingleNode("TableTitles").Cast <XmlNode>().Select(n => n.InnerText).ToList() : new List <string>(),
                    TableColumnCount         = node.ChildNodes.Cast <XmlNode>().Where(n => n.Name == "TableTitles").Count(),
                    FurtherInfo              = furtherInfoExists ? node.SelectSingleNode("FurtherInfo").Cast <XmlNode>().Select(n => n.InnerText).ToList() : null,
                    Reference                = referenceExists ? node.SelectSingleNode("Reference").InnerText : "Missing Reference",
                    HasAdditionalInformation = furtherInfoExists,
                    HasTable                 = tableTitleNodeExists,
                    ItemType                 = typeOfTestReportItem
                };

                testReportItem.TestReportItems = testStandardsExist ? node.SelectSingleNode("TestStandards").Cast <XmlNode>().Select(n => ParseXmlNodeToTestReportItem(n, ref depth)).ToList() : null;
                depth--;
                Debug.WriteLine(depth);
            }
            catch (XmlException ex)
            {
                Debug.WriteLine(string.Format("XmlException for test name: {0}", ex.Message));

                testReportItem = new TestReportItem()
                {
                    Title = $"Error Occured - { node.Name } something went wrong trying to read this object in the directory.",
                };
            }

            return(testReportItem);
        }
        public async Task GetReportDeserializer_CorrectlyDeserializesReportAsync()
        {
            var expectedItem0 = new TestReportItem(1234, "Bob", 86.25f);
            var expectedItem1 = new TestReportItem(1237, "Mary", 90.5f);

            GetReportContext <TestReport> context = GetReportContext <TestReport>();

            await this.pipelineElement.ProcessAsync(context, NullLogger.Instance, default).ConfigureAwait(false);

            const int expectedCount = 2;

            Assert.AreEqual(expectedCount, context.Results.Report.Count, $"Expected {expectedCount} items in the report.");
            Assert.AreEqual(context.Results.Report[0], expectedItem0);
            Assert.AreEqual(context.Results.Report[1], expectedItem1);
        }