Exemplo n.º 1
0
        private Dictionary<string, string> CreateRunInfo(XDocument doc, Report report, string resultsFile)
        {
            var result = new Dictionary<string, string>();
            if (doc.Root.Element("environment") == null)
                return result;

            var runInfo = new RunInfo
            {
                TestParser = TypeName
            };

            var env = doc.Descendants("environment").First();
            runInfo.Info.Add("Test Results File", resultsFile);

            if (env.Attribute("nunit-version") != null)
                runInfo.Info.Add("NUnit Version", env.GetAttributeValueOrDefault("nunit-version"));
            runInfo.Info.Add("Assembly Name", report.AssemblyName);
            runInfo.Info.Add("OS Version", env.GetAttributeValueOrDefault("os-version"));
            runInfo.Info.Add("Platform", env.GetAttributeValueOrDefault("platform"));
            runInfo.Info.Add("CLR Version", env.GetAttributeValueOrDefault("clr-version"));
            runInfo.Info.Add("Machine Name", env.GetAttributeValueOrDefault("machine-name"));
            runInfo.Info.Add("User", env.GetAttributeValueOrDefault("user"));
            runInfo.Info.Add("User Domain", env.GetAttributeValueOrDefault("user-domain"));

            return runInfo.Info;
        }
Exemplo n.º 2
0
 private string GetArtifactsDirectoryFor(Report report)
 {
     var artifactPath = Path.Combine(".\\Artifacts\\", report.FileName);
     var fullArtifactPath = Path.Combine(_outputDirectory, artifactPath);
     if (!Directory.Exists(fullArtifactPath))
         Directory.CreateDirectory(fullArtifactPath);
     return artifactPath;
 }
Exemplo n.º 3
0
 public void SaveOriginalXmlContents(Report report)
 {
     var artifactBaseDirectory = GetArtifactsDirectoryFor(report);
     var inputXmlFileContents = report.XmlFileContents;
     var inputXmlFilePath = Path.Combine(_outputDirectory, artifactBaseDirectory, $"{report.FileName}.xml");
     using (var inputFile = File.CreateText(inputXmlFilePath))
     {
         inputFile.Write(inputXmlFileContents);
     }
 }
Exemplo n.º 4
0
        public void AddReport(Report report)
        {
            if (_reportList == null)
            {
                _reportList = new List<Report>();
            }

            _reportList.Add(report);

            SideNavLinks += Engine.Razor.RunCompile(Templates.SideNav.Link, "sidenav", typeof(Report), report, null);
        }
Exemplo n.º 5
0
        private RunInfo CreateRunInfo(XContainer doc, Report report)
        {
            // run-info & environment values -> RunInfo
            var runInfo = new RunInfo { TestRunner = report.TestRunner };

            runInfo.Info.Add("TestRunner Version", "");
            runInfo.Info.Add("File", report.FileName);

            runInfo.Info.Add("Machine Name", doc.Descendants(_xns + "UnitTestResult").First().Attribute("computerName").Value);

            return runInfo;
        }
Exemplo n.º 6
0
 public void CopyReportedArtifacts(Report report)
 {
     var artifactBaseDirectory = GetArtifactsDirectoryFor(report);
     foreach (var test in GetTestsFrom(report))
     {
         var artifactPath = Path.Combine(artifactBaseDirectory, test.ArtifactSet.DirectoryName);
         Directory.CreateDirectory(Path.Combine(_outputDirectory, artifactPath));
         foreach (var artifact in test.ArtifactSet.Artifacts)
         {
             artifact.FilePath = Path.Combine(artifactPath, artifact.FileName).Replace("\\", "/");
             File.Copy(
                 Path.Combine(test.ArtifactSet.BasePath, artifact.FileName),
                 Path.Combine(_outputDirectory, artifact.FilePath), true);
         }
     }
 }
Exemplo n.º 7
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Inconclusive")
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted")
                    || x.Attribute("outcome").Value.Equals("disconnected")
                    || x.Attribute("outcome").Value.Equals("notRunnable")
                    || x.Attribute("outcome").Value.Equals("warning")
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Passed")
                    || x.Attribute("outcome").Value.Equals("Aborted")
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests

            return report;
        }
Exemplo n.º 8
0
        public static Report Parse(XDocument reportDoc)
        {
            var report = new Report();

            // report counts
            report.Total = reportDoc.Descendants("test-case").Count();

            report.Passed = GetCountableAttributeOrDefault(reportDoc.Root, "passed");
            if(report.Passed == 0)
            {
                report.Passed = reportDoc
                    .Descendants("test-case")
                    .Count(x => x.Attribute("executed").Value == "True" && x.Attribute("success").Value == "True");
            }

            report.Failed = GetCountableAttributeOrDefault(reportDoc.Root, "failures");
            report.Errors = GetCountableAttributeOrDefault(reportDoc.Root, "errors");

            report.Inconclusive = GetCountableAttributeOrDefault(reportDoc.Root, "inconclusive");
            report.Inconclusive += GetCountableAttributeOrDefault(reportDoc.Root, "not-run");

            report.Skipped = GetCountableAttributeOrDefault(reportDoc.Root, "skipped");
            report.Skipped += GetCountableAttributeOrDefault(reportDoc.Root, "ignored");

            // report duration
            report.StartTime = reportDoc.Root.GetAttributeValueOrDefault("start-time")
                            ?? string.Format("{0} {1}",
                                reportDoc.Root.GetAttributeValueOrDefault("date"),
                                reportDoc.Root.GetAttributeValueOrDefault("time")).Trim();

            report.EndTime = reportDoc.Root.GetAttributeValueOrDefault("end-time");

            // report status messages
            var testSuiteTypeAssembly = reportDoc.Descendants("test-suite")
                .Where(x => x.Attribute("result").Value.Equals("Failed") && x.Attribute("type").Value.Equals("Assembly"));

            report.StatusMessage = testSuiteTypeAssembly != null && testSuiteTypeAssembly.Count() > 0
                ? testSuiteTypeAssembly.First().Value
                : "";

            return report;
        }
Exemplo n.º 9
0
        private RunInfo CreateRunInfo(XDocument doc, Report report)
        {
            // run-info & environment values -> RunInfo
            RunInfo runInfo = new RunInfo();

            runInfo.TestParser = TypeName;
            runInfo.Info.Add("TestRunner Version", "");
            runInfo.Info.Add("File", report.FileName);

            runInfo.Info.Add("Machine Name", doc.Descendants(xns + "UnitTestResult").First().Attribute("computerName").Value);

            return runInfo;
        }
Exemplo n.º 10
0
        public Report Parse(string resultsFile)
        {
            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(xns + "files").First().Descendants(xns + "file").First().Value;
            report.TestParser = this;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(xns + "testStep")
                .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(xns + "statistics").First();
            report.Total = tests.Count();
            report.Passed = Int32.Parse(statistics.Attribute("passedCount").Value);
            report.Failed = Int32.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = Int32.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped = Int32.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors = 0;

            // report duration
            XElement testPackageRun = doc.Descendants(xns + "testPackageRun").First();
            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime = testPackageRun.Attribute("endTime").Value;

            var suitesList = new List<string>();
            TestSuite testSuite = null;

            tests.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    testSuite = new TestSuite();
                    testSuite.Name = testSuiteName;
                    testSuite.StartTime = tc.Parent.Attribute("startTime").Value;
                    testSuite.EndTime = tc.Parent.Attribute("endTime").Value;

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Model.Test();

                test.Name = tc.Attribute("name").Value;
                test.Status = StatusExtensions.ToStatus(tc.Parent.Descendants(xns + "outcome").First().Attribute("status").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.AddStatus(test.Status);

                var entry = tc.Descendants(xns + "entry");

                // description
                var description = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Description"))
                    : null;
                test.Description =  description != null && description.Count() > 0
                    ? description.First().Value
                    : "";

                // error and other status messages
                var ignoreReason = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"))
                    : null;
                test.StatusMessage = ignoreReason != null && ignoreReason.Count() > 0
                    ? ignoreReason.First().Value
                    : "";

                var testLog = tc.Parent.Descendants(xns + "testLog");
                test.StatusMessage += testLog != null && testLog.Count() > 0
                    ? testLog.First().Value
                    : "";

                // assign categories
                var category = entry != null
                    ? entry.Where(x => x.Attribute("key").Value.Equals("Category"))
                    : null;
                if (category != null && category.Count() > 0)
                {
                    category.ToList().ForEach(s =>
                    {
                        string cat = s.Value;

                        test.CategoryList.Add(cat);
                        report.AddCategory(cat);
                    });
                }

                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return report;
        }
Exemplo n.º 11
0
        private RunInfo CreateRunInfo(XDocument doc, Report report)
        {
            // run-info & environment values -> RunInfo
            RunInfo runInfo = new RunInfo();

            runInfo.TestParser = TypeName;
            runInfo.Info.Add("File", report.AssemblyName);

            var children = doc.Descendants(xns + "children").First();

            var testKind = children.Descendants(xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("TestKind", StringComparison.CurrentCultureIgnoreCase));
            var testKindValue = testKind != null && testKind.Count() > 0
                ? testKind.First().Descendants(xns + "value").First().Value
                : "";
            runInfo.Info.Add("TestKind", testKindValue);

            var codebase = children.Descendants(xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("CodeBase", StringComparison.CurrentCultureIgnoreCase));
            var codebaseValue = codebase != null && codebase.Count() > 0
                ? codebase.First().Descendants(xns + "value").First().Value
                : "";
            runInfo.Info.Add("CodeBase", codebaseValue);

            var framework = children.Descendants(xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("Framework", StringComparison.CurrentCultureIgnoreCase));
            var frameworkValue = framework != null && framework.Count() > 0
                ? testKind.First().Descendants(xns + "value").First().Value
                : "";
            runInfo.Info.Add("Framework", frameworkValue);

            var version = children.Descendants(xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("Version", StringComparison.CurrentCultureIgnoreCase));
            var versionValue = version != null && version.Count() > 0
                ? testKind.First().Descendants(xns + "value").First().Value
                : "";
            runInfo.Info.Add("Version", versionValue);

            return runInfo;
        }
Exemplo n.º 12
0
        public Report Parse(string resultsFile)
        {
            this.resultsFile = resultsFile;

            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Root.Attribute("name").Value;
            report.TestRunner = TestRunner.NUnit;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report);
            report.AddRunInfo(runInfo.Info);

            // report counts
            report.Total = doc.Descendants("test-case").Count();

            report.Passed =
                doc.Root.Attribute("passed") != null
                    ? Int32.Parse(doc.Root.Attribute("passed").Value)
                    : doc.Descendants("test-case").Where(x => x.Attribute("result").Value.Equals("success", StringComparison.CurrentCultureIgnoreCase)).Count();

            report.Failed =
                doc.Root.Attribute("failed") != null
                    ? Int32.Parse(doc.Root.Attribute("failed").Value)
                    : Int32.Parse(doc.Root.Attribute("failures").Value);

            report.Errors =
                doc.Root.Attribute("errors") != null
                    ? Int32.Parse(doc.Root.Attribute("errors").Value)
                    : 0;

            report.Inconclusive =
                doc.Root.Attribute("inconclusive") != null
                    ? Int32.Parse(doc.Root.Attribute("inconclusive").Value)
                    : Int32.Parse(doc.Root.Attribute("inconclusive").Value);

            report.Skipped =
                doc.Root.Attribute("skipped") != null
                    ? Int32.Parse(doc.Root.Attribute("skipped").Value)
                    : Int32.Parse(doc.Root.Attribute("skipped").Value);

            report.Skipped +=
                doc.Root.Attribute("ignored") != null
                    ? Int32.Parse(doc.Root.Attribute("ignored").Value)
                    : 0;

            // report duration
            report.StartTime =
                doc.Root.Attribute("start-time") != null
                    ? doc.Root.Attribute("start-time").Value
                    : doc.Root.Attribute("date").Value + " " + doc.Root.Attribute("time").Value;

            report.EndTime =
                doc.Root.Attribute("end-time") != null
                    ? doc.Root.Attribute("end-time").Value
                    : "";

            IEnumerable<XElement> suites = doc
                .Descendants("test-suite")
                .Where(x => x.Attribute("type").Value.Equals("TestFixture", StringComparison.CurrentCultureIgnoreCase));

            suites.AsParallel().ToList().ForEach(ts =>
            {
                var testSuite = new TestSuite();
                testSuite.Name = ts.Attribute("name").Value;

                // Suite Time Info
                testSuite.StartTime =
                    ts.Attribute("start-time") != null
                        ? ts.Attribute("start-time").Value
                        : string.Empty;

                testSuite.StartTime =
                    String.IsNullOrEmpty(testSuite.StartTime) && ts.Attribute("time") != null
                        ? ts.Attribute("time").Value
                        : testSuite.StartTime;

                testSuite.EndTime =
                    ts.Attribute("end-time") != null
                        ? ts.Attribute("end-time").Value
                        : "";

                // any error messages or stack-trace
                testSuite.StatusMessage =
                    ts.Element("failure") != null
                        ? ts.Element("failure").Element("message").Value
                        : "";

                // Test Cases
                ts.Descendants("test-case").AsParallel().ToList().ForEach(tc =>
                {
                    var test = new Model.Test();

                    test.Name = tc.Attribute("name").Value;
                    test.Status = StatusExtensions.ToStatus(tc.Attribute("result").Value);

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    // TestCase Time Info
                    test.StartTime =
                        tc.Attribute("start-time") != null
                            ? tc.Attribute("start-time").Value
                            : "";
                    test.StartTime =
                        String.IsNullOrEmpty(test.StartTime) && (tc.Attribute("time") != null)
                            ? tc.Attribute("time").Value
                            : test.StartTime;
                    test.EndTime =
                        tc.Attribute("end-time") != null
                            ? tc.Attribute("end-time").Value
                            : "";

                    // description
                    var description =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Description", StringComparison.CurrentCultureIgnoreCase));
                    test.Description =
                        description.Count() > 0
                            ? description.ToArray()[0].Attribute("value").Value
                            : "";

                    bool hasCategories =
                        tc.Descendants("property")
                        .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase)).Count() > 0;

                    if (hasCategories)
                    {
                        List<XElement> cats = tc
                            .Descendants("property")
                            .Where(c => c.Attribute("name").Value.Equals("Category", StringComparison.CurrentCultureIgnoreCase))
                            .ToList();

                        cats.ForEach(x =>
                        {
                            string cat = x.Attribute("value").Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }

                    // error and other status messages
                    test.StatusMessage =
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("message").Value
                            : "";
                    test.StatusMessage +=
                        tc.Element("failure") != null
                            ? tc.Element("failure").Element("stack-trace") != null
                                ? tc.Element("failure").Element("stack-trace").Value
                                : ""
                            : "";

                    testSuite.TestList.Add(test);
                });

                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);

                report.TestSuiteList.Add(testSuite);
            });

            return report;
        }
Exemplo n.º 13
0
        private RunInfo CreateRunInfo(XDocument doc, Report report)
        {
            RunInfo runInfo = new RunInfo();
            runInfo.TestRunner = report.TestRunner;

            XElement env = doc.Descendants("environment").First();
            runInfo.Info.Add("Test Results File", resultsFile);
            runInfo.Info.Add("NUnit Version", env.Attribute("nunit-version").Value);
            runInfo.Info.Add("Assembly Name", report.AssemblyName);
            runInfo.Info.Add("OS Version", env.Attribute("os-version").Value);
            runInfo.Info.Add("Platform", env.Attribute("platform").Value);
            runInfo.Info.Add("CLR Version", env.Attribute("clr-version").Value);
            runInfo.Info.Add("Machine Name", env.Attribute("machine-name").Value);
            runInfo.Info.Add("User", env.Attribute("user").Value);
            runInfo.Info.Add("User Domain", env.Attribute("user-domain").Value);

            return runInfo;
        }
Exemplo n.º 14
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Inconclusive") 
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted") 
                    || x.Attribute("outcome").Value.Equals("disconnected") 
                    || x.Attribute("outcome").Value.Equals("notRunnable") 
                    || x.Attribute("outcome").Value.Equals("warning") 
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x => 
                    x.Attribute("outcome").Value.Equals("Passed") 
                    || x.Attribute("outcome").Value.Equals("Aborted") 
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";
                test.Duration = TimeSpan.Parse(tc.Attribute("duration").Value).TotalMilliseconds;

                // error and other status messages
                test.StatusMessage =
                    tc.Element(xns + "Output") != null
                        ? tc.Element(xns + "Output").Value.Trim()
                        : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").Where(x => x.Attribute("name").Value.Equals(test.Name));
                if (unitTestElement != null && unitTestElement.Count() > 0)
                {
                    var className = unitTestElement.First().Element(xns + "TestMethod").Attribute("className").Value;
                    var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(className));

                    if (testSuite == null)
                    {
                        testSuite = new TestSuite();
                        testSuite.Name = className;

                        report.TestSuiteList.Add(testSuite);
                    }

                    testSuite.TestList.Add(test);
                    testSuite.Duration += test.Duration;
                    testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
                }
            });

            return report;
        }
Exemplo n.º 15
0
 private IEnumerable<Test> GetTestsFrom(Report report)
 {
     return report.TestSuiteList
         .SelectMany(suite => suite.TestList)
         .Where(t => t.HasArtifacts());
 }
Exemplo n.º 16
0
        public Report Parse(string resultsFile)
        {
            XDocument doc = XDocument.Load(resultsFile);

            Report report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.TestRunner = TestRunner.MSTest2010;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // report counts
            var resultNodes = doc.Descendants(xns + "UnitTestResult");
            report.Total = resultNodes.Count();
            report.Passed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Passed")).Count();
            report.Failed = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("Failed")).Count();
            report.Inconclusive = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Inconclusive")
                    || x.Attribute("outcome").Value.Equals("passedButRunAborted")
                    || x.Attribute("outcome").Value.Equals("disconnected")
                    || x.Attribute("outcome").Value.Equals("notRunnable")
                    || x.Attribute("outcome").Value.Equals("warning")
                    || x.Attribute("outcome").Value.Equals("pending"))
                .Count();
            report.Skipped = resultNodes.Where(x => x.Attribute("outcome").Value.Equals("NotExecuted")).Count();
            report.Errors = resultNodes
                .Where(x =>
                    x.Attribute("outcome").Value.Equals("Passed")
                    || x.Attribute("outcome").Value.Equals("Aborted")
                    || x.Attribute("outcome").Value.Equals("timeout"))
                .Count();

            // report duration
            XElement times = doc.Descendants(xns + "Times").First();
            report.StartTime = times.Attribute("start").Value;
            report.EndTime = times.Attribute("finish").Value;

            // ToDo: add fixtures + tests
            doc.Descendants(xns + "UnitTestResult").AsParallel().ToList().ForEach(tc =>
            {
                var test = new Model.Test();

                test.Name = tc.Attribute("testName").Value;
                test.Status = StatusExtensions.ToStatus(tc.Attribute("outcome").Value);

                // main a master list of all status
                // used to build the status filter in the view
                report.StatusList.Add(test.Status);

                // TestCase Time Info
                test.StartTime =
                    tc.Attribute("startTime") != null
                        ? tc.Attribute("startTime").Value
                        : "";
                test.EndTime =
                    tc.Attribute("endTime") != null
                        ? tc.Attribute("endTime").Value
                        : "";

                var timespan = Convert.ToDateTime(test.StartTime) - Convert.ToDateTime(test.EndTime);
                test.Duration = timespan.Milliseconds;

                // error and other status messages
                test.StatusMessage = tc.Element(xns + "Output") != null ? tc.Element(xns + "Output").Value.Trim() : "";

                var unitTestElement = doc.Descendants(xns + "UnitTest").FirstOrDefault(x => x.Attribute("name").Value.Equals(test.Name));

                if (unitTestElement != null)
                {
                    
                    var descriptionElement = unitTestElement.Element(xns + "Description");
                    if (descriptionElement != null)
                    {
                        test.Description = descriptionElement.Value;
                    }

                    var categories = (from testCategory in unitTestElement.Descendants(xns + "TestCategoryItem")
                                          select testCategory.Attributes("TestCategory").Select(x => x.Value).FirstOrDefault()).ToList();
                    
                    test.CategoryList = categories;
                    
                    
                    if (categories.Any())
                    {
                        foreach (var suiteName in categories)
                        {
                            AddTestToSuite(report, test, suiteName);
                        }
                    }
                    else
                    {
                        var suiteName = unitTestElement.Element(xns + "TestMethod").Attribute("className").Value;
                        AddTestToSuite(report, test, suiteName);
                    }
                }
            });

            report.TestSuiteList = report.TestSuiteList.OrderBy(x => x.Name).ToList();

            return report;
        }
Exemplo n.º 17
0
        private static void AddTestToSuite(Report report, Test test, string suiteName)
        {
            var testSuite = report.TestSuiteList.SingleOrDefault(t => t.Name.Equals(suiteName));

            if (testSuite == null)
            {
                testSuite = new TestSuite { Name = suiteName };
                report.TestSuiteList.Add(testSuite);
            }

            testSuite.TestList.Add(test);
            testSuite.Duration += test.Duration;
            testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
        }
Exemplo n.º 18
0
        private RunInfo CreateRunInfo(XContainer doc, Report report)
        {
            // run-info & environment values -> RunInfo
            var runInfo = new RunInfo();

            runInfo.TestRunner = report.TestRunner;
            runInfo.Info.Add("File", report.AssemblyName);

            var children = doc.Descendants(_xns + "children").First();

            var testKind = children.Descendants(_xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("TestKind", StringComparison.CurrentCultureIgnoreCase));
            var xElements = testKind as XElement[] ?? testKind.ToArray();
            var testKindValue = xElements.Any()
                ? xElements.First().Descendants(_xns + "value").First().Value
                : "";
            runInfo.Info.Add("TestKind", testKindValue);

            var codebase = children.Descendants(_xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("CodeBase", StringComparison.CurrentCultureIgnoreCase));
            var enumerable = codebase as XElement[] ?? codebase.ToArray();
            var codebaseValue = enumerable.Any()
                ? enumerable.First().Descendants(_xns + "value").First().Value
                : "";
            runInfo.Info.Add("CodeBase", codebaseValue);

            var framework = children.Descendants(_xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("Framework", StringComparison.CurrentCultureIgnoreCase));
            var frameworkValue = framework.Any()
                ? xElements.First().Descendants(_xns + "value").First().Value
                : "";
            runInfo.Info.Add("Framework", frameworkValue);

            var version = children.Descendants(_xns + "entry")
                .Where(x => x.Attribute("key").Value.Equals("Version", StringComparison.CurrentCultureIgnoreCase));
            var versionValue = version.Any()
                ? xElements.First().Descendants(_xns + "value").First().Value
                : "";
            runInfo.Info.Add("Version", versionValue);

            return runInfo;
        }
Exemplo n.º 19
0
        public Report Parse(string resultsFile)
        {
            ResultsFile = resultsFile;

            var doc = XDocument.Load(resultsFile);

            var report = new Report();

            report.FileName = Path.GetFileNameWithoutExtension(resultsFile);
            report.AssemblyName = doc.Descendants(_xns + "files").First().Descendants(_xns + "file").First().Value;
            report.TestRunner = TestRunner.Gallio;

            // run-info & environment values -> RunInfo
            var runInfo = CreateRunInfo(doc, report).Info;
            report.AddRunInfo(runInfo);

            // test cases
            var tests = doc.Descendants(_xns + "testStep")
                .Where(x => x.Attribute("isTestCase").Value.Equals("true", StringComparison.CurrentCultureIgnoreCase));

            // report counts
            var statistics = doc.Descendants(_xns + "statistics").First();
            var xElements = tests as XElement[] ?? tests.ToArray();
            report.Total = xElements.Count();
            report.Passed = int.Parse(statistics.Attribute("passedCount").Value);
            report.Failed = int.Parse(statistics.Attribute("failedCount").Value);
            report.Inconclusive = int.Parse(statistics.Attribute("inconclusiveCount").Value);
            report.Skipped = int.Parse(statistics.Attribute("skippedCount").Value);
            report.Errors = 0;

            // report duration
            var testPackageRun = doc.Descendants(_xns + "testPackageRun").First();
            report.StartTime = testPackageRun.Attribute("startTime").Value;
            report.EndTime = testPackageRun.Attribute("endTime").Value;

            var suitesList = new List<string>();
            TestSuite testSuite = null;

            xElements.AsParallel().ToList().ForEach(tc =>
            {
                var testSuiteName = tc.Attribute("fullName").Value;
                testSuiteName = testSuiteName.Contains('/')
                    ? testSuiteName.Split('/')[testSuiteName.Split('/').Length - 2]
                    : testSuiteName;

                if (!suitesList.Contains(testSuiteName))
                {
                    if (tc.Parent != null)
                        testSuite = new TestSuite
                        {
                            Name = testSuiteName,
                            StartTime = tc.Parent.Attribute("startTime").Value,
                            EndTime = tc.Parent.Attribute("endTime").Value
                        };

                    report.TestSuiteList.Add(testSuite);

                    suitesList.Add(testSuiteName);
                }

                var test = new Test
                {
                    Name = tc.Attribute("name").Value
                };

                if (tc.Parent != null)
                {
                    test.Status = tc.Parent.Descendants(_xns + "outcome").First().Attribute("status").Value.ToStatus();

                    // main a master list of all status
                    // used to build the status filter in the view
                    report.StatusList.Add(test.Status);

                    var entry = tc.Descendants(_xns + "entry");

                    // description
                    var enumerable = entry as XElement[] ?? entry.ToArray();
                    var description = enumerable.Where(x => x.Attribute("key").Value.Equals("Description"));
                    var elements = description as XElement[] ?? description.ToArray();
                    test.Description = elements.Any()
                        ? elements.First().Value
                        : "";

                    // error and other status messages
                    var ignoreReason = enumerable.Where(x => x.Attribute("key").Value.Equals("IgnoreReason"));
                    var reason = ignoreReason as XElement[] ?? ignoreReason.ToArray();
                    test.StatusMessage = reason.Any()
                        ? reason.First().Value
                        : "";

                    if (tc.Parent != null)
                    {
                        var testLog = tc.Parent.Descendants(_xns + "testLog");
                        var log = testLog as XElement[] ?? testLog.ToArray();
                        test.StatusMessage += log.Any()
                            ? log.First().Value
                            : "";
                    }

                    // assign categories
                    var category = enumerable.Where(x => x.Attribute("key").Value.Equals("Category"));
                    var xElements1 = category as XElement[] ?? category.ToArray();
                    if (xElements1.Any())
                    {
                        xElements1.ToList().ForEach(s =>
                        {
                            var cat = s.Value;

                            test.CategoryList.Add(cat);
                            report.CategoryList.Add(cat);
                        });
                    }
                }

                if (testSuite == null) return;
                testSuite.TestList.Add(test);
                testSuite.Status = ReportUtil.GetFixtureStatus(testSuite.TestList);
            });

            return report;
        }