Example #1
0
        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();
        }
Example #2
0
        private string GenerateReportingItemSection(ReportingItemSection section)
        {
            StringBuilder report = new StringBuilder();

            string cellDefinitionHtml        = "<td bgcolor=\"<!--BGCOLOR-->\"><font face=\"Calibri\" size=\"2\" color=\"<!--TEXTCOLOR-->\"><!--VALUE--></font></td>";
            string headingCellDefinitionHtml = "<td bgcolor=\"<!--BGCOLOR-->\" <!--WIDTH-->><font face=\"Calibri\" size=\"2\" color=\"<!--TEXTCOLOR-->\"><b><!--VALUE--></b></font></td>";
            string fontsize = section.SectionTitleFontSize == 0 ? "3" : section.SectionTitleFontSize.ToString();

            string headingRowHtml = "<table border=\"0\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">" +
                                    "<tr><!--INDENTCELLS--><td bgcolor=\"" + ColorTranslator.ToHtml(section.SectionTitleBackgroundColor) + "\" colspan=\"1\">" +
                                    "<font face=\"Calibri\" size=\"" + fontsize + "\" color=\"" + ColorTranslator.ToHtml(section.SectionTitleTextColor) + "\">" +
                                    "<b>" + CleanHtml(section.SectionTitle) + "</b></font></td></tr></table>";


            for (int x = 0; x < section.IndentLevel; x++)
            {
                headingRowHtml = headingRowHtml.Replace("<!--INDENTCELLS-->", "<td width=\"15\"></td><!--INDENTCELLS-->");
            }

            headingRowHtml = headingRowHtml.Replace("<!--INDENTCELLS-->", string.Empty);

            report.AppendLine(headingRowHtml);
            report.AppendLine("<table width=\"100%\">");

            if (section.ColumnHeadings.Count > 0)
            {
                report.AppendLine("<tr>");

                for (int x = 0; x < section.IndentLevel; x++)
                {
                    report.AppendLine("<td width=\"15\"></td>");
                }

                foreach (ColumnHeader cell in section.ColumnHeadings)
                {
                    string width = string.Empty;

                    if (section.AutoEqualColumnWidth)
                    {
                        decimal percent = ((decimal)1 / section.ColumnHeadings.Count) * 100;
                        width = string.Format("{0}", percent.ToString("F2") + "%");
                    }
                    else
                    {
                        if (cell.ColumnWidthPx != 0)
                        {
                            width = string.Format("{0}", cell.ColumnWidthPx);
                        }
                        else if (cell.ColumnWidthPercent != 0)
                        {
                            width = string.Format("{0}", cell.ColumnWidthPercent.ToString("F2") + "%");
                        }
                    }

                    string cellHtml = headingCellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(cell.ValueBackgroundColor));
                    cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(cell.ValueTextColor));
                    cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(cell.Value));
                    cellHtml = cellHtml.Replace("<!--WIDTH-->", "width=\"" + width + "\"");
                    report.AppendLine(cellHtml);
                }
                report.AppendLine("</tr>");
            }
            else
            {
                cellDefinitionHtml = cellDefinitionHtml.Replace("<!--WIDTH-->", "\"100%\"");
            }


            foreach (ReportingItem item in section.ReportingItems)
            {
                report.AppendLine("<tr>");

                for (int x = 0; x < section.IndentLevel; x++)
                {
                    report.AppendLine("<td width=\"15\"></td>");
                }

                string titleCellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(item.TitleBackgroundColor));
                titleCellHtml = titleCellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(item.TitleTextColor));
                titleCellHtml = titleCellHtml.Replace("<!--VALUE-->", CleanHtml(item.Title));
                report.AppendLine(titleCellHtml);

                foreach (ReportingCell value in item.ReportingItemValues)
                {
                    string cellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(value.ValueBackgroundColor));
                    cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(value.ValueTextColor));
                    cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(value.Value));
                    report.AppendLine(cellHtml);
                }

                // Add in any blank cells required to make a full row
                if (item.ReportingItemValues.Count < section.ColumnHeadings.Count - 1)
                {
                    int           additionalCellsRequired = section.ColumnHeadings.Count - item.ReportingItemValues.Count;
                    ReportingCell emptyCell = new ReportingCell();

                    for (int x = 0; x < additionalCellsRequired; x++)
                    {
                        string cellHtml = cellDefinitionHtml.Replace("<!--BGCOLOR-->", ColorTranslator.ToHtml(emptyCell.ValueBackgroundColor));
                        cellHtml = cellHtml.Replace("<!--TEXTCOLOR-->", ColorTranslator.ToHtml(emptyCell.ValueTextColor));
                        cellHtml = cellHtml.Replace("<!--VALUE-->", CleanHtml(emptyCell.Value));
                        report.AppendLine(cellHtml);
                    }
                }

                report.AppendLine("</tr>");
            }

            report.AppendLine("</table>");
            report.AppendLine("<br>");

            return(report.ToString());
        }
Example #3
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);
        }