/// <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);
        }
示例#2
0
        /// <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();
        }