private static void TestReport() { Report report = new Report(); report.VersionText = "my report 1.1.1.1"; report.ReportHeading = new ReportingCell("My test report", System.Drawing.Color.Red); ReportingItemSection section = new ReportingItemSection(); section.SectionTitle = "First section"; section.SectionTitleBackgroundColor = System.Drawing.Color.Black; section.SectionTitleTextColor = System.Drawing.Color.White; section.AddHeading("Item"); section.AddHeading("Value1"); section.AddHeading("Value2"); section.AddReportingItem("my item1", "value1", "value5"); section.AddReportingItem("my item2", "value2", "value6"); section.AddReportingItem("my item3", "value3", "value7"); section.AddReportingItem("my item4", "value4", "value8"); report.AddSection(section); section = new ReportingItemSection(); section.SectionTitle = "Second section"; section.SectionTitleBackgroundColor = System.Drawing.Color.Red; section.SectionTitleTextColor = System.Drawing.Color.White; section.AddHeading("Item"); section.AddHeading("Value1"); section.AddReportingItem("my item1", "value1"); section.AddReportingItem("my item2", "value2"); section.AddReportingItem("my item3", "value3"); section.AddReportingItem("my item4", "value4"); report.AddSection(section); TextSection textsection = new TextSection(); textsection.SectionTitle = "Third section"; textsection.SectionTitleBackgroundColor = System.Drawing.Color.Green; textsection.Text = "my preformatted text\r\non a new line as well"; report.AddSection(textsection); string html = report.GenerateHtmlReport(); }
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); }