< Summary

Information
Class: Amusoft.DotnetNew.Tests.Diagnostics.TestResult
Assembly: Amusoft.DotnetNew.Tests
File(s): /home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Diagnostics/TestResult.cs
Tag: 127_14865883074
Line coverage
97%
Covered lines: 35
Uncovered lines: 1
Coverable lines: 36
Total lines: 69
Line coverage: 97.2%
Branch coverage
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.cctor()100%11100%
GetTestResultLines()75%8.51880%
GetXunit2Lines()100%11100%
GetXunit3Lines()100%11100%
Print(...)100%11100%

File(s)

/home/runner/work/Amusoft.DotnetNew.Tests/Amusoft.DotnetNew.Tests/src/Amusoft.DotnetNew.Tests/Diagnostics/TestResult.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using System.Text;
 4using System.Text.Json;
 5using System.Text.RegularExpressions;
 6using Amusoft.DotnetNew.Tests.Interfaces;
 7using Amusoft.DotnetNew.Tests.Templating;
 8using Amusoft.DotnetNew.Tests.Utility;
 9
 10namespace Amusoft.DotnetNew.Tests.Diagnostics;
 11
 312internal class TestResult(
 313  string command,
 314  string content
 315) : ICommandResult
 16{
 17  // old:.A total of 1 test files matched the specified pattern.Passed!  - Failed:     0, Passed:     1, Skipped:     0,
 18  // new: Test summary: total: 1; failed: 0; succeeded: 1; skipped: 0; duration: 1,2s
 19  // new: Amusoft.Toolkit.Mvvm.Wpf.IntegrationTests test net8.0 succeeded (2,7s)
 120  private static readonly Regex Xunit2Regex = new(@"Passed!\s*-\s*Failed:\s*(?<failed>\d+),\s*Passed:\s*(?<passed>\d+),\
 121  private static readonly Regex Xunit3Regex = new(@"Test summary: total: [\d]+; failed: [\d]+; succeeded: [\d]+; skipped
 22
 23  private IEnumerable<string> GetTestResultLines()
 24  {
 325    if (GetXunit2Lines() is { Length: > 0 } xunit2)
 226      return xunit2;
 127    if (GetXunit3Lines() is { Length: > 0 } xunit3)
 128      return xunit3;
 29
 030    return [];
 31  }
 32
 33  private string[] GetXunit2Lines()
 34  {
 335    var matchCollection = Xunit2Regex.Matches(content);
 336    return matchCollection
 437      .Select(match => (content: match.Value.Replace(match.Groups["duration"].Value, "SCRUBBED"), sort: match.Groups["pr
 438      .OrderBy(d => d.sort)
 439      .Select(d => d.content.Trim())
 340      .ToArray();
 41  }
 42
 43  private string[] GetXunit3Lines()
 44  {
 145    var matchCollection = Xunit3Regex.Matches(content);
 146    return matchCollection
 747      .Select(match => (content: match.Value.Replace(match.Groups["duration"].Value, " SCRUBBED "), sort: match.Groups["
 748      .OrderBy(d => d.sort)
 749      .Select(d => d.content.Trim())
 150      .ToArray();
 51  }
 52
 53  public void Print(StringBuilder stringBuilder)
 54  {
 355    var serializeContent = new
 356    {
 357      Command = command,
 358      Lines = GetTestResultLines(),
 359    };
 360    var serialized = JsonSerializer.Serialize(serializeContent,new JsonSerializerOptions()
 361      {
 362        WriteIndented = true,
 363        Encoder = CustomJsonEncoder.Instance
 364      }
 365    );
 66
 367    stringBuilder.Append(TemplatingDefaults.Instance.PrintPattern("TestResult", serialized));
 368  }
 69}