/// <summary> /// Creates a class report. /// </summary> /// <param name="reportRenderer">The report renderer.</param> /// <param name="class">The class.</param> /// <param name="fileAnalyses">The file analyses that correspond to the class.</param> public virtual void CreateClassReport(IReportRenderer reportRenderer, Class @class, IEnumerable <FileAnalysis> fileAnalyses) { if (reportRenderer == null) { throw new ArgumentNullException(nameof(reportRenderer)); } if (@class == null) { throw new ArgumentNullException(nameof(@class)); } if (fileAnalyses == null) { throw new ArgumentNullException(nameof(fileAnalyses)); } reportRenderer.BeginClassReport(this.ReportContext.ReportConfiguration.TargetDirectory, @class.Assembly.ShortName, @class.Name); reportRenderer.HeaderWithBackLink(ReportResources.Summary); reportRenderer.BeginKeyValueTable(); reportRenderer.KeyValueRow(ReportResources.Class, @class.Name); reportRenderer.KeyValueRow(ReportResources.Assembly, @class.Assembly.ShortName); reportRenderer.KeyValueRow(ReportResources.Files3, @class.Files.Select(f => f.Path)); reportRenderer.KeyValueRow(ReportResources.CoveredLines, @class.CoveredLines.ToString(CultureInfo.InvariantCulture)); reportRenderer.KeyValueRow(ReportResources.UncoveredLines, (@class.CoverableLines - @class.CoveredLines).ToString(CultureInfo.InvariantCulture)); reportRenderer.KeyValueRow(ReportResources.CoverableLines, @class.CoverableLines.ToString(CultureInfo.InvariantCulture)); reportRenderer.KeyValueRow(ReportResources.TotalLines, @class.TotalLines.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)); reportRenderer.KeyValueRow(ReportResources.Coverage2, @class.CoverageQuota.HasValue ? $"{@class.CoverageQuota.Value.ToString(CultureInfo.InvariantCulture)}% ({@class.CoveredLines.ToString(CultureInfo.InvariantCulture)} {ReportResources.Of} {@class.CoverableLines.ToString(CultureInfo.InvariantCulture)})" : string.Empty); if (@class.CoveredBranches.HasValue && @class.TotalBranches.HasValue) { reportRenderer.KeyValueRow(ReportResources.CoveredBranches2, @class.CoveredBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)); reportRenderer.KeyValueRow(ReportResources.TotalBranches, @class.TotalBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)); decimal?branchCoverage = @class.BranchCoverageQuota; if (branchCoverage.HasValue) { reportRenderer.KeyValueRow(ReportResources.BranchCoverage2, $"{branchCoverage.Value.ToString(CultureInfo.InvariantCulture)}% ({@class.CoveredBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)} {ReportResources.Of} {@class.TotalBranches.GetValueOrDefault().ToString(CultureInfo.InvariantCulture)})"); } } if (this.ReportContext.ReportConfiguration.Tag != null) { reportRenderer.KeyValueRow(ReportResources.Tag, this.ReportContext.ReportConfiguration.Tag); } reportRenderer.FinishTable(); if (reportRenderer.SupportsCharts) { if (@class.HistoricCoverages.Any(h => h.CoverageQuota.HasValue || h.BranchCoverageQuota.HasValue)) { reportRenderer.Header(ReportResources.History); reportRenderer.Chart(@class.HistoricCoverages, this.ReportContext.Settings.RenderPngFallBackImagesForHistoryCharts); } } if (@class.Files.Any(f => f.MethodMetrics.Any())) { reportRenderer.Header(ReportResources.Metrics); reportRenderer.MetricsTable(@class); } reportRenderer.Header(ReportResources.Files); if (fileAnalyses.Any()) { int fileIndex = 0; foreach (var fileAnalysis in fileAnalyses) { reportRenderer.File(fileAnalysis.Path); if (!string.IsNullOrEmpty(fileAnalysis.Error)) { reportRenderer.Paragraph(fileAnalysis.Error); } else { reportRenderer.BeginLineAnalysisTable(new[] { string.Empty, "#", ReportResources.Line, string.Empty, ReportResources.Coverage }); foreach (var line in fileAnalysis.Lines) { reportRenderer.LineAnalysis(fileIndex, line); } reportRenderer.FinishTable(); } fileIndex++; } } else { reportRenderer.Paragraph(ReportResources.NoFilesFound); } reportRenderer.AddFooter(); if (fileAnalyses.Any()) { var testMethods = @class.Files .SelectMany(f => f.TestMethods) .Distinct() .OrderBy(l => l.ShortName); var codeElementsByFileIndex = new Dictionary <int, IEnumerable <CodeElement> >(); int fileIndex = 0; foreach (var file in @class.Files) { codeElementsByFileIndex.Add(fileIndex++, file.CodeElements.OrderBy(c => c.FirstLine)); } reportRenderer.TestMethods(testMethods, fileAnalyses, codeElementsByFileIndex); } reportRenderer.SaveClassReport(this.ReportContext.ReportConfiguration.TargetDirectory, @class.Assembly.ShortName, @class.Name); }
/// <summary> /// Creates a class report. /// </summary> /// <param name="reportRenderer">The report renderer.</param> /// <param name="codeFile"></param> /// <param name="fileAnalysis">The file analyses that correspond to the class.</param> /// <param name="sourceFile">The source file.</param> public virtual void CreateFileReport(IReportRenderer reportRenderer, CodeFile codeFile, FileAnalysis fileAnalysis) { if (reportRenderer == null) { throw new ArgumentNullException(nameof(reportRenderer)); } if (fileAnalysis == null) { throw new ArgumentNullException(nameof(fileAnalysis)); } string additionalTitle = this.ReportContext.ReportConfiguration.Title != null ? $"{this.ReportContext.ReportConfiguration.Title} - " : null; reportRenderer.BeginFileReport(this.ReportContext.ReportConfiguration.TargetDirectory, codeFile.Path, additionalTitle); if (this.ReportContext.ReportConfiguration.Title != null) { reportRenderer.HeaderWithBackLink($"{ReportResources.Summary} - {this.ReportContext.ReportConfiguration.Title}"); } else { reportRenderer.HeaderWithBackLink(ReportResources.Summary); } reportRenderer.BeginKeyValueTable(); reportRenderer.KeyValueRow(ReportResources.Files3, codeFile.Path); reportRenderer.KeyValueRow(ReportResources.CoveredLines, Convert.ToString(codeFile.CoveredLines, CultureInfo.CurrentUICulture)); reportRenderer.KeyValueRow(ReportResources.UncoveredLines, Convert.ToString(codeFile.CoverableLines - codeFile.CoveredLines, CultureInfo.CurrentUICulture)); reportRenderer.KeyValueRow(ReportResources.CoverableLines, Convert.ToString(codeFile.CoverableLines, CultureInfo.CurrentUICulture)); reportRenderer.KeyValueRow(ReportResources.TotalLines, Convert.ToString(codeFile.TotalLines, CultureInfo.CurrentUICulture)); if (this.ReportContext.ReportConfiguration.Tag != null) { reportRenderer.KeyValueRow(ReportResources.Tag, this.ReportContext.ReportConfiguration.Tag); } reportRenderer.FinishTable(); if (codeFile.MethodMetrics.Any()) { reportRenderer.Header(ReportResources.Metrics); reportRenderer.MetricsTable(codeFile.MethodMetrics); } reportRenderer.Header(ReportResources.Files); reportRenderer.File(codeFile.Path); if (!string.IsNullOrEmpty(fileAnalysis.Error)) { reportRenderer.Paragraph(fileAnalysis.Error); } else { reportRenderer.BeginLineAnalysisTable(new[] { string.Empty, "#", ReportResources.Line, string.Empty, ReportResources.Coverage }); foreach (var line in fileAnalysis.Lines) { reportRenderer.LineAnalysis(0, line); } reportRenderer.FinishTable(); } reportRenderer.AddFooter(); { var testMethods = codeFile.TestMethods.OrderBy(l => l.ShortName); var codeElementsByFileIndex = new Dictionary <int, IEnumerable <CodeElement> >(); int fileIndex = 0; codeElementsByFileIndex.Add(fileIndex++, codeFile.CodeElements.OrderBy(c => c.FirstLine)); reportRenderer.TestMethods(testMethods, new[] { fileAnalysis }, codeElementsByFileIndex); } reportRenderer.SaveClassReport(this.ReportContext.ReportConfiguration.TargetDirectory, null, null); }