Пример #1
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(LineAnalysis analysis)
        {
            if (analysis == null)
            {
                throw new ArgumentNullException("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);
            formattedLine = XmlRenderer.ReplaceInvalidXmlChars(formattedLine);

            string lineVisitStatus = "gray";

            if (analysis.LineVisitStatus == LineVisitStatus.Covered)
            {
                lineVisitStatus = "green";
            }
            else if (analysis.LineVisitStatus == LineVisitStatus.NotCovered)
            {
                lineVisitStatus = "red";
            }

            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="analysis">The line analysis.</param>
        public void LineAnalysis(LineAnalysis analysis)
        {
            if (analysis == null)
            {
                throw new ArgumentNullException("analysis");
            }

            var coverage = new XElement(
                "LineAnalysis",
                new XAttribute("line", analysis.LineNumber),
                new XAttribute("visits", analysis.LineVisits),
                new XAttribute("coverage", analysis.LineVisitStatus),
                new XAttribute("content", analysis.LineContent));

            this.currentFile.Add(coverage);
        }
Пример #3
0
 /// <summary>
 /// Adds the given line analysis to the file analysis.
 /// </summary>
 /// <param name="lineAnalysis">The line analysis.</param>
 internal void AddLineAnalysis(LineAnalysis lineAnalysis)
 {
     this.lineAnalysis.Add(lineAnalysis);
 }
Пример #4
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(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

            if (formattedLine.Length > 120)
            {
                formattedLine = formattedLine.Substring(0, 120);
            }

            formattedLine = WebUtility.HtmlEncode(formattedLine);
            formattedLine = formattedLine.Replace(" ", "&nbsp;");

            string lineVisitStatus = ConvertToCssClass(analysis.LineVisitStatus, false);

            string title = null;
            if (analysis.CoveredBranches.HasValue && analysis.TotalBranches.HasValue && analysis.TotalBranches.Value > 0)
            {
                title = string.Format(ReportResources.CoveredBranches, analysis.CoveredBranches, analysis.TotalBranches);
            }

            if (title != null)
            {
                this.reportTextWriter.Write("<tr title=\"{0}\" data-coverage=\"{{", title);
            }
            else
            {
                this.reportTextWriter.Write("<tr data-coverage=\"{");
            }

            this.reportTextWriter.Write(
                "'AllTestMethods': {{'VC': '{0}', 'LVS': '{1}'}}",
                analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty,
                lineVisitStatus);

            foreach (var coverageByTestMethod in analysis.LineCoverageByTestMethod)
            {
                this.reportTextWriter.Write(
                    ", 'M{0}': {{'VC': '{1}', 'LVS': '{2}'}}",
                    coverageByTestMethod.Key.Id.ToString(CultureInfo.InvariantCulture),
                    coverageByTestMethod.Value.LineVisitStatus != LineVisitStatus.NotCoverable ? coverageByTestMethod.Value.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty,
                    ConvertToCssClass(coverageByTestMethod.Value.LineVisitStatus, false));
            }

            this.reportTextWriter.Write("}\">");

            this.reportTextWriter.Write(
                "<td class=\"{0}\">&nbsp;</td>",
                lineVisitStatus);
            this.reportTextWriter.Write(
                "<td class=\"leftmargin rightmargin right\">{0}</td>",
                analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty);
            this.reportTextWriter.Write(
                "<td class=\"rightmargin right\"><code>{0}</code></td>",
                analysis.LineNumber);

            if (title != null)
            {
                int branchCoverage = (int)(100 * (double)analysis.CoveredBranches.Value / analysis.TotalBranches.Value);
                branchCoverage -= branchCoverage % 10;
                this.reportTextWriter.Write("<td class=\"branch coverage{0}\">&nbsp;</td>", branchCoverage);
            }
            else
            {
                this.reportTextWriter.Write("<td></td>");
            }

            this.reportTextWriter.Write(
                "<td class=\"{0}\"><code>{1}</code></td>",
                ConvertToCssClass(analysis.LineVisitStatus, true),
                formattedLine);

            this.reportTextWriter.WriteLine("</tr>");
        }
Пример #5
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(LineAnalysis analysis)
        {
            if (analysis == null)
            {
                throw new ArgumentNullException("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("content", analysis.LineContent);
            this.reportTextWriter.WriteEndElement();
        }
 /// <summary>
 /// Adds the coverage information of a single line of a file to the report.
 /// </summary>
 /// <param name="analysis">The line analysis.</param>
 public void LineAnalysis(LineAnalysis analysis)
 {
     foreach (var renderer in this.renderers)
     {
         renderer.LineAnalysis(analysis);
     }
 }
Пример #7
0
 /// <summary>
 /// Adds the given line analysis to the file analysis.
 /// </summary>
 /// <param name="lineAnalysis">The line analysis.</param>
 internal void AddLineAnalysis(LineAnalysis lineAnalysis)
 {
     this.lineAnalysis.Add(lineAnalysis);
 }
Пример #8
0
 /// <summary>
 /// Adds the given line analysis to the file analysis.
 /// </summary>
 /// <param name="lineAnalysis">The line analysis.</param>
 public void AddLineAnalysis(LineAnalysis lineAnalysis)
 {
     this.lineAnalysis.Add(lineAnalysis);
 }
Пример #9
0
 /// <summary>
 /// Adds the given line analysis to the file analysis.
 /// </summary>
 /// <param name="lineAnalysis">The line analysis.</param>
 public void AddLineAnalysis(LineAnalysis lineAnalysis)
 {
     this.lineAnalysis.Add(lineAnalysis);
 }
Пример #10
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(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();
        }
Пример #11
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(LineAnalysis analysis)
        {
            if (analysis == null)
            {
                throw new ArgumentNullException("analysis");
            }

            string formattedLine = analysis.LineContent
                .Replace(((char)11).ToString(), "  ") // replace tab
                .Replace(((char)9).ToString(), "  "); // replace tab

            if (formattedLine.Length > 120)
            {
                formattedLine = formattedLine.Substring(0, 120);
            }

            formattedLine = WebUtility.HtmlEncode(formattedLine);
            formattedLine = formattedLine.Replace(" ", "&nbsp;");

            string lineVisitStatus = "gray";

            if (analysis.LineVisitStatus == LineVisitStatus.Covered)
            {
                lineVisitStatus = "green";
            }
            else if (analysis.LineVisitStatus == LineVisitStatus.NotCovered)
            {
                lineVisitStatus = "red";
            }

            this.reportBuilder.AppendLine("<tr>");

            this.reportBuilder.AppendFormat(
                CultureInfo.InvariantCulture,
                "<td class=\"{0}\">&nbsp;</td>",
                lineVisitStatus);
            this.reportBuilder.AppendFormat(
                CultureInfo.InvariantCulture,
                "<td class=\"leftmargin right\">{0}</td>",
                analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty);
            this.reportBuilder.AppendFormat(
                CultureInfo.InvariantCulture,
                "<td class=\"right\"><code>{0}</code></td>",
                analysis.LineNumber);
            this.reportBuilder.AppendFormat(
                CultureInfo.InvariantCulture,
                "<td{0}><code>{1}</code></td>",
                analysis.LineVisitStatus == LineVisitStatus.NotCoverable ? " class=\"light\"" : string.Empty,
                formattedLine);

            this.reportBuilder.AppendLine("</tr>");
        }
Пример #12
0
        /// <summary>
        /// Adds the coverage information of a single line of a file to the report.
        /// </summary>
        /// <param name="analysis">The line analysis.</param>
        public void LineAnalysis(LineAnalysis analysis)
        {
            if (analysis == null)
            {
                throw new ArgumentNullException("analysis");
            }

            string formattedLine = analysis.LineContent
                .Replace(((char)11).ToString(), "  ") // replace tab
                .Replace(((char)9).ToString(), "  "); // replace tab

            if (formattedLine.Length > 120)
            {
                formattedLine = formattedLine.Substring(0, 120);
            }

            formattedLine = WebUtility.HtmlEncode(formattedLine);
            formattedLine = formattedLine.Replace(" ", "&nbsp;");

            string lineVisitStatus = ConvertToCssClass(analysis.LineVisitStatus, false);

            this.reportTextWriter.Write("<tr data-coverage=\"{");

            this.reportTextWriter.Write(
                "'AllTestMethods': {{'VC': '{0}', 'LVS': '{1}'}}",
                analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty,
                lineVisitStatus);

            foreach (var coverageByTestMethod in analysis.LineCoverageByTestMethod)
            {
                this.reportTextWriter.Write(
                    ", 'M{0}': {{'VC': '{1}', 'LVS': '{2}'}}",
                    coverageByTestMethod.Key.Id.ToString(CultureInfo.InvariantCulture),
                    coverageByTestMethod.Value.LineVisitStatus != LineVisitStatus.NotCoverable ? coverageByTestMethod.Value.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty,
                    ConvertToCssClass(coverageByTestMethod.Value.LineVisitStatus, false));
            }

            this.reportTextWriter.Write("}\">");

            this.reportTextWriter.Write(
                "<td class=\"{0}\">&nbsp;</td>",
                lineVisitStatus);
            this.reportTextWriter.Write(
                "<td class=\"leftmargin rightmargin right\">{0}</td>",
                analysis.LineVisitStatus != LineVisitStatus.NotCoverable ? analysis.LineVisits.ToString(CultureInfo.InvariantCulture) : string.Empty);
            this.reportTextWriter.Write(
                "<td class=\"rightmargin right\"><code>{0}</code></td>",
                analysis.LineNumber);
            this.reportTextWriter.Write(
                "<td class=\"{0}\"><code>{1}</code></td>",
                ConvertToCssClass(analysis.LineVisitStatus, true),
                formattedLine);

            this.reportTextWriter.WriteLine("</tr>");
        }