/// <summary> /// Adds metrics to the report /// </summary> /// <param name="methodMetrics">The method metrics.</param> public void MetricsTable(IEnumerable <MethodMetric> methodMetrics) { if (methodMetrics == null) { throw new ArgumentNullException(nameof(methodMetrics)); } foreach (var methodMetric in methodMetrics.OrderBy(c => c.Line)) { this.reportTextWriter.WriteStartElement("Element"); this.reportTextWriter.WriteAttributeString("name", XmlRenderer.ReplaceNonLetterChars(methodMetric.ShortName)); foreach (var m in methodMetric.Metrics) { this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceNonLetterChars(m.Name)); if (m.Value.HasValue) { this.reportTextWriter.WriteValue(m.Value.Value.ToString(CultureInfo.InvariantCulture)); } this.reportTextWriter.WriteEndElement(); } this.reportTextWriter.WriteEndElement(); } this.reportTextWriter.WriteEndElement(); }
/// <summary> /// Adds the coverage information of a single line of a file to the report. /// </summary> /// <param name="fileIndex">The index of the file.</param> /// <param name="analysis">The line analysis.</param> public void LineAnalysis(int fileIndex, LineAnalysis analysis) { if (analysis == null) { throw new ArgumentNullException(nameof(analysis)); } string formattedLine = analysis.LineContent .Replace(((char)11).ToString(), " ") // replace tab .Replace(((char)9).ToString(), " ") // replace tab .Replace("~", " "); // replace '~' since this used for the \verb command formattedLine = ShortenString(formattedLine, 120); formattedLine = XmlRenderer.ReplaceInvalidXmlChars(formattedLine); string lineVisitStatus; switch (analysis.LineVisitStatus) { case LineVisitStatus.Covered: lineVisitStatus = "green"; break; case LineVisitStatus.NotCovered: lineVisitStatus = "red"; break; case LineVisitStatus.PartiallyCovered: lineVisitStatus = "orange"; break; default: lineVisitStatus = "gray"; break; } string row = string.Format( CultureInfo.InvariantCulture, @"\cellcolor{{{0}}} & {1} & \verb~{2}~ & & \verb~{3}~\\", lineVisitStatus, analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty, analysis.LineNumber, formattedLine); this.reportTextWriter.WriteLine(row); }
/// <summary> /// Adds the coverage information of a single line of a file to the report. /// </summary> /// <param name="fileIndex">The index of the file.</param> /// <param name="analysis">The line analysis.</param> public void LineAnalysis(int fileIndex, LineAnalysis analysis) { if (analysis == null) { throw new ArgumentNullException(nameof(analysis)); } this.reportTextWriter.WriteStartElement("LineAnalysis"); this.reportTextWriter.WriteAttributeString("line", analysis.LineNumber.ToString(CultureInfo.InvariantCulture)); this.reportTextWriter.WriteAttributeString("visits", analysis.LineVisits.ToString(CultureInfo.InvariantCulture)); this.reportTextWriter.WriteAttributeString("coverage", analysis.LineVisitStatus.ToString()); this.reportTextWriter.WriteAttributeString("coveredbranches", analysis.CoveredBranches.HasValue ? analysis.CoveredBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty); this.reportTextWriter.WriteAttributeString("totalbranches", analysis.TotalBranches.HasValue ? analysis.TotalBranches.Value.ToString(CultureInfo.InvariantCulture) : string.Empty); this.reportTextWriter.WriteAttributeString("content", XmlRenderer.ReplaceInvalidXmlChars(analysis.LineContent)); this.reportTextWriter.WriteEndElement(); }
/// <summary> /// Adds a table row with two cells to the report. /// </summary> /// <param name="key">The text of the first column.</param> /// <param name="files">The files.</param> public void KeyValueRow(string key, IEnumerable <string> files) { if (files == null) { throw new ArgumentNullException(nameof(files)); } this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceNonLetterChars(key)); foreach (var file in files) { this.reportTextWriter.WriteStartElement("File"); this.reportTextWriter.WriteValue(file); this.reportTextWriter.WriteEndElement(); } this.reportTextWriter.WriteEndElement(); }
/// <summary> /// Adds a header to the report. /// </summary> /// <param name="text">The text.</param> public void Header(string text) { this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceNonLetterChars(text)); }
/// <summary> /// Adds a table row with two cells to the report. /// </summary> /// <param name="key">The text of the first column.</param> /// <param name="value">The text of the second column.</param> public void KeyValueRow(string key, string value) { this.reportTextWriter.WriteStartElement(XmlRenderer.ReplaceNonLetterChars(key)); this.reportTextWriter.WriteValue(value); this.reportTextWriter.WriteEndElement(); }