Пример #1
0
        /// <summary>
        /// Creates the summary report.
        /// </summary>
        /// <param name="reportRenderer">The report renderer.</param>
        /// <param name="summaryResult">The summary result.</param>
        public virtual void CreateSummaryReport(IReportRenderer reportRenderer, SummaryResult summaryResult)
        {
            if (reportRenderer == null)
            {
                throw new ArgumentNullException(nameof(reportRenderer));
            }

            if (summaryResult == null)
            {
                throw new ArgumentNullException(nameof(summaryResult));
            }

            reportRenderer.BeginSummaryReport(this.TargetDirectory, null, ReportResources.Summary);
            //reportRenderer.Header(ReportResources.Summary);
            int val;

            if (summaryResult.TestedNewLines != 0 && summaryResult.NewLines != 0 && summaryResult.CoverableLines != 0)
            {
                val = (int)((summaryResult.CoverableLines == 0) ? (decimal?)null : (decimal)Math.Truncate(100 * ((double)summaryResult.TestedNewLines / (double)summaryResult.NewLines)));
            }
            else
            {
                val = 0;
            }
            string value = val != 0 ? val.ToString(CultureInfo.InvariantCulture) + "%" : "0%";

            reportRenderer.Begindiv(summaryResult.BuildVersion, value);

            reportRenderer.BeginKeyValueTable1();
            //reportRenderer.KeyValueRow(ReportResources.GeneratedOn, DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToLongTimeString());
            //reportRenderer.KeyValueRow(ReportResources.Parser, summaryResult.UsedParser);
            reportRenderer.KeyValueRow(ReportResources.Assemblies2, summaryResult.Assemblies.Count().ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.Classes, summaryResult.Assemblies.SelectMany(a => a.Classes).Count().ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.Files2, summaryResult.Assemblies.SelectMany(a => a.Classes).SelectMany(a => a.Files).Distinct().Count().ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.CoveredLines, summaryResult.CoveredLines.ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.UncoveredLines, (summaryResult.CoverableLines - summaryResult.CoveredLines).ToString(CultureInfo.InvariantCulture));
            //reportRenderer.KeyValueRow(ReportResources.NewLines, summaryResult.NewLines.ToString(CultureInfo.InvariantCulture));
            //reportRenderer.KeyValueRow(ReportResources.TestedNewLines, summaryResult.TestedNewLines.ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.TotalLines, summaryResult.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.Coverage2, summaryResult.CoverageQuota.HasValue ? summaryResult.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "%" : string.Empty);
            //reportRenderer.KeyValueRow(ReportResources.TestCoverage, val != 0 ? val.ToString(CultureInfo.InvariantCulture) + "%" : "0%");
            //reportRenderer.KeyValueRow(ReportResources.TestCoverage, summaryResult.CoverageQuota.HasValue ? summaryResult.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture) + "%" : string.Empty);
            decimal?branchCoverage = summaryResult.BranchCoverageQuota;

            if (branchCoverage.HasValue)
            {
                reportRenderer.KeyValueRow(ReportResources.BranchCoverage2, branchCoverage.Value.ToString(CultureInfo.InvariantCulture) + "%");
            }

            reportRenderer.FinishTable();

            reportRenderer.BeginKeyValueTable2();
            reportRenderer.KeyValueRow(ReportResources.ModifiedAssemblies, summaryResult.modifyassemblies.ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.NewLines, summaryResult.NewLines.ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.TestedNewLines, summaryResult.TestedNewLines.ToString(CultureInfo.InvariantCulture));
            reportRenderer.KeyValueRow(ReportResources.TestCoverage, val != 0 ? val.ToString(CultureInfo.InvariantCulture) + "%" : "0%");

            reportRenderer.FinishTable();

            reportRenderer.Enddiv();

            var historicCoverages = this.GetOverallHistoricCoverages(summaryResult.Assemblies.SelectMany(a => a.Classes));

            if (historicCoverages.Any(h => h.CoverageQuota.HasValue || h.BranchCoverageQuota.HasValue))
            {
                reportRenderer.Header(ReportResources.History);
                reportRenderer.Chart(historicCoverages);
            }

            reportRenderer.Header(ReportResources.Assemblies);

            if (summaryResult.Assemblies.Any())
            {
                reportRenderer.BeginSummaryTable(summaryResult.SupportsBranchCoverage);

                //foreach (var assembly in summaryResult.Assemblies)
                //{
                //    reportRenderer.SummaryAssembly(assembly, summaryResult.SupportsBranchCoverage);

                //    foreach (var @class in assembly.Classes)
                //    {
                //        reportRenderer.SummaryClass(@class, summaryResult.SupportsBranchCoverage);
                //    }
                //}

                //reportRenderer.FinishTable();
            }
            else
            {
                reportRenderer.Paragraph(ReportResources.NoCoveredAssemblies);
            }

            reportRenderer.CustomSummary(summaryResult.Assemblies, summaryResult.SupportsBranchCoverage);
            reportRenderer.AddFooter();
            reportRenderer.SaveSummaryReport(this.TargetDirectory);
        }