コード例 #1
0
ファイル: Reporting.cs プロジェクト: ryannewington/acma
        public ReportingItem AddReportingItem(string title, string value)
        {
            ReportingItem item = new ReportingItem();

            item.Title = title;
            item.AddValue(value);
            this.ReportingItems.Add(item);
            return(item);
        }
コード例 #2
0
        public void ToHtml(string filename)
        {
            Report report = new Report();

            report.ReportHeading = new ReportingCell("ACMA Unit Test Report");
            report.VersionText   = System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString(3);

            if (this.TestErrorCount > 0)
            {
                report.ReportSubHeading = new ReportingCell("Errors were encountered during the test run", this.GetResultColor(UnitTestResult.Error));
            }
            else if (this.TestFailedCount > 0)
            {
                report.ReportSubHeading = new ReportingCell("One or more unit tests failed", this.GetResultColor(UnitTestResult.Failed));
            }
            else if (this.TestInconclusiveCount > 0)
            {
                report.ReportSubHeading = new ReportingCell("One or more unit test results were inconclusive", this.GetResultColor(UnitTestResult.Inconclusive));
            }
            else if (this.TestSuccessfulCount == 0)
            {
                report.ReportSubHeading = new ReportingCell("No unit tests were executed", Color.Black);
            }
            else
            {
                report.ReportSubHeading = new ReportingCell("The unit test run was successful", this.GetResultColor(UnitTestResult.Passed));
            }

            ReportingItemSection parameters = new ReportingItemSection();

            parameters.SectionTitle = "Test Parameters";
            parameters.AddReportingItem("Test file", this.TestFile);
            parameters.AddReportingItem("ACMA configuration file", this.ConfigFile);
            parameters.AddReportingItem("SQL server", this.Server);
            parameters.AddReportingItem("Database", this.Database);

            report.Sections.Add(parameters);

            ReportingItemSection stats = new ReportingItemSection();

            stats.SectionTitle = "Test Statistics";
            stats.AddReportingItem("Test count", this.TestCount.ToString());
            stats.AddReportingItem("Successful tests", string.Format("{0} ({1}%)", this.TestSuccessfulCount.ToString(), this.TestSuccessfulPercent.ToString("D")));
            stats.AddReportingItem("Failed tests", string.Format("{0} ({1}%)", this.TestFailedCount.ToString(), this.TestFailedPercent.ToString("D")));
            stats.AddReportingItem("Inconclusive tests", string.Format("{0} ({1}%)", this.TestInconclusiveCount.ToString(), this.TestInconclusivePercent.ToString("D")));
            stats.AddReportingItem("Errored tests", string.Format("{0} ({1}%)", this.TestErrorCount.ToString(), this.TestErrorPercent.ToString("D")));
            stats.AddReportingItem("Test start time", this.StartTime.ToString("g"));
            stats.AddReportingItem("Test end time", this.EndTime.ToString("g"));
            stats.AddReportingItem("Test duration", this.Duration.ToString("g"));
            stats.AddReportingItem("Test per second", this.TestsPerSecond.ToString("F2"));

            report.AddSection(stats);

            ReportingItemSection results = new ReportingItemSection();

            results.SectionTitle = "Test Results";
            results.AddHeading("Result", Color.Black, Color.LightGray);
            results.AddHeading("Test ID", Color.Black, Color.LightGray);
            results.AddHeading("Test description", Color.Black, Color.LightGray);
            results.AddHeading("Result description", Color.Black, Color.LightGray);


            foreach (UnitTestOutcome outcome in this.Outcomes)
            {
                ReportingItem item = new ReportingItem();
                item.Title = outcome.Result.ToString();
                item.TitleBackgroundColor = this.GetResultColor(outcome.Result);
                item.TitleTextColor       = Color.Black;
                item.AddValue(outcome.Test.ID);
                item.AddValue(outcome.Test.Description);
                item.AddValue(outcome.Description);
                results.ReportingItems.Add(item);
            }

            report.AddSection(results);

            string content = report.GenerateHtmlReport();

            File.WriteAllText(filename, content);
        }