示例#1
0
    public static string Format(TestReport report, TestFormatFlags flags)
    {
        var builder = new StringBuilder();

        if ((flags & TestFormatFlags.Markdown) == TestFormatFlags.Markdown)
        {
            FormatMd(builder, report, flags);
        }
        else
        {
            FormatText(builder, report, flags);
        }

        return(builder.ToString());
    }
示例#2
0
    private static void FormatMd(StringBuilder sb, TestReport report, TestFormatFlags flags)
    {
        sb.AppendLine("# " + string.Format(Header, DateTime.Now));
        sb.AppendLine();

        sb.AppendLine("## " + SummaryHeader);
        sb.AppendLine(string.Format(Summary,
                                    report.Results.Count(r => r.Error is null),
                                    report.Results.Count(r => r.Error is not null).ToString() + (report.FailedFiles.Any() ? "1+" : ""),
                                    report.TestFiles.Length
                                    ));
        sb.AppendLine();

        sb.AppendLine("## " + FileHeader2);
        sb.AppendLine(string.Join(", ", report.TestFiles
                                  .Select(f => "[" + Path.GetFileName(f) + "](" + Path.GetFullPath(f) + ")")));
        sb.AppendLine();

        if (report.BuildWarnings != null && report.BuildWarnings.Count > 0)
        {
            sb.AppendLine("## " + Warnings);

            foreach (var w in report.BuildWarnings)
            {
                sb.Append("* " + w);
            }

            sb.AppendLine();
        }

        IEnumerable <TestResult> results;
        var onlyFailed = (flags & TestFormatFlags.OnlyFailed) == TestFormatFlags.OnlyFailed;

        if (onlyFailed)
        {
            results = report.Results.Where(r => r.Error is not null);
        }
        else
        {
            results = report.Results;
        }

        if (!onlyFailed || results.Any())
        {
            sb.AppendLine("## " + Report);
            sb.AppendLine();

            foreach (var group in results.GroupBy(r => r.FileName))
            {
                sb.AppendLine("### " + GetShortFileName(group.Key));

                foreach (var f in group)
                {
                    if (f.Error is null)
                    {
                        sb.AppendLine("* &#9745; **" + f.Name + "**");
                    }
                    else if (f.Name is not null)
                    {
                        sb.AppendLine("* &#9746; **" + f.Name + "**: " + f.Error);
                    }
                    else
                    {
                        sb.AppendLine("* &#9746; " + f.Error);
                    }
                }

                sb.AppendLine();
            }
        }
    }
示例#3
0
    private static void FormatText(StringBuilder sb, TestReport report, TestFormatFlags flags)
    {
        sb.AppendLine(string.Format(Header, DateTime.Now));
        sb.AppendLine();
        sb.AppendLine(string.Format(FileHeader1, report.TestFiles.Length));
        sb.AppendLine(string.Join(", ", report.TestFiles.Select(Path.GetFileName)));
        sb.AppendLine();

        if (report.BuildWarnings != null && report.BuildWarnings.Count > 0)
        {
            sb.AppendLine(Warnings);

            foreach (var w in report.BuildWarnings)
            {
                sb.Append(w);
            }

            sb.AppendLine();
        }

        IEnumerable <TestResult> results;
        var onlyFailed = (flags & TestFormatFlags.OnlyFailed) == TestFormatFlags.OnlyFailed;

        if (onlyFailed)
        {
            results = report.Results.Where(r => r.Error is not null);
        }
        else
        {
            results = report.Results;
        }

        if (!onlyFailed || results.Any())
        {
            sb.AppendLine(Report);
            sb.AppendLine();

            foreach (var group in results.GroupBy(r => r.FileName))
            {
                sb.AppendLine(GetShortFileName(group.Key));

                foreach (var f in group)
                {
                    if (f.Error is null)
                    {
                        sb.AppendLine("[+] \"" + f.Name + "\"");
                    }
                    else if (f.Name is not null)
                    {
                        sb.AppendLine("[ ] \"" + f.Name + "\": " + f.Error);
                    }
                    else
                    {
                        sb.AppendLine("[ ] " + f.Error);
                    }
                }

                sb.AppendLine();
            }
        }

        sb.AppendLine(SummaryHeader);
        sb.AppendLine(string.Format(Summary,
                                    report.Results.Count(r => r.Error is null),
                                    report.Results.Count(r => r.Error is not null).ToString() + (report.FailedFiles.Any() ? "1+" : ""),
                                    report.TestFiles.Length
                                    ));
    }