< Summary

Information
Class: DirectSight.Parser.ParserResult
Assembly DirectSight
File(s): /home/runner/work/DirectSight/DirectSight/DirectSight/Parser/ParserResult.cs
Line coverage
69%
Covered lines: 60
Uncovered lines: 26
Coverable lines: 86
Total lines: 192
Line coverage: 69.7%
Branch coverage
50%
Covered branches: 11
Total branches: 22
Branch coverage: 50%
Method coverage

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor()100%11100%
.ctor(...)50%22100%
Merge(...)50%121266.66%
Min(...)0%220%
Max(...)0%220%

File(s)

/home/runner/work/DirectSight/DirectSight/DirectSight/Parser/ParserResult.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using DirectSight.Parser.Analysis;
 6
 7namespace DirectSight.Parser;
 8
 9/// <summary>
 10/// The result on a <see cref="ParserBase"/>.
 11/// </summary>
 12public class ParserResult
 13{
 14    /// <summary>
 15    /// The name of the parser or the merged parsers.
 16    /// </summary>
 17    private readonly List<string> parserNames;
 18
 19    /// <summary>
 20    /// The covered assemblies.
 21    /// </summary>
 22    private readonly List<Assembly> assemblies;
 23
 24    /// <summary>
 25    /// Initializes a new instance of the <see cref="ParserResult"/> class.
 26    /// </summary>
 827    public ParserResult()
 828    {
 829        this.assemblies = [];
 830        this.SupportsBranchCoverage = false;
 831        this.parserNames = [];
 832    }
 33
 34    /// <summary>
 35    /// Initializes a new instance of the <see cref="ParserResult"/> class.
 36    /// </summary>
 37    /// <param name="assemblies">The assemblies.</param>
 38    /// <param name="supportsBranchCoverage">Indicates whether the used parser supports branch coverage.</param>
 39    /// <param name="parserName">The name of the parser.</param>
 9040    public ParserResult(List<Assembly> assemblies, bool supportsBranchCoverage, string parserName)
 9041    {
 9042        ArgumentNullException.ThrowIfNull(parserName);
 43
 9044        this.assemblies = assemblies ?? throw new ArgumentNullException(nameof(assemblies));
 9045        this.SupportsBranchCoverage = supportsBranchCoverage;
 9046        this.parserNames =
 9047        [
 9048            parserName
 9049        ];
 9050    }
 51
 52    /// <summary>
 53    /// Gets the assemblies that have been found in the report.
 54    /// </summary>
 55    /// <value>The assemblies.</value>
 8256    public IReadOnlyCollection<Assembly> Assemblies => this.assemblies;
 57
 58    /// <summary>
 59    /// Gets a value indicating whether the used parser supports branch coverage.
 60    /// </summary>
 61    /// <value>
 62    /// <c>true</c> if used parser supports branch coverage; otherwise, <c>false</c>.
 63    /// </value>
 19664    public bool SupportsBranchCoverage { get; private set; }
 65
 66    /// <summary>
 67    /// Gets the timestamp on which the coverage report was generated.
 68    /// </summary>
 9269    public DateTime? MinimumTimeStamp { get; internal set; }
 70
 71    /// <summary>
 72    /// Gets the timestamp on which the coverage report was generated.
 73    /// </summary>
 9274    public DateTime? MaximumTimeStamp { get; internal set; }
 75
 76    /// <summary>
 77    /// Gets the names of the parsers.
 78    /// </summary>
 79    public string ParserName
 80    {
 81        get
 582        {
 583            if (this.parserNames.Count == 0)
 184            {
 185                return string.Empty;
 86            }
 487            else if (this.parserNames.Count == 1)
 388            {
 389                return this.parserNames[0];
 90            }
 91            else
 192            {
 193                var sb = new StringBuilder("MultiReport (");
 94
 495                var groupedParsers = this.parserNames.GroupBy(p => p).OrderBy(pg => pg.Key);
 96
 197                sb.Append(string.Join(
 198                    ", ",
 299                    groupedParsers.Select(pg => string.Format("{0}x {1}", pg.Count(), pg.Key))));
 100
 1101                sb.Append(')');
 1102                return sb.ToString();
 103            }
 5104        }
 105    }
 106
 107    /// <summary>
 108    /// Merges the given parser result with the current instance.
 109    /// </summary>
 110    /// <param name="parserResult">The parser result to merge.</param>
 111    internal void Merge(ParserResult parserResult)
 30112    {
 148113        foreach (var assembly in parserResult.Assemblies)
 29114        {
 52115            var existingAssembly = this.assemblies.FirstOrDefault(a => a.Name == assembly.Name);
 116
 29117            if (existingAssembly != null)
 23118            {
 23119                existingAssembly.Merge(assembly);
 23120            }
 121            else
 6122            {
 6123                this.assemblies.Add(assembly);
 6124            }
 29125        }
 126
 30127        this.assemblies.Sort((x, y) => x.Name.CompareTo(y.Name));
 128
 30129        this.SupportsBranchCoverage |= parserResult.SupportsBranchCoverage;
 30130        this.parserNames.AddRange(parserResult.parserNames);
 131
 30132        if (this.MinimumTimeStamp.HasValue)
 0133        {
 0134            if (parserResult.MinimumTimeStamp.HasValue)
 0135            {
 0136                this.MinimumTimeStamp = Min(this.MinimumTimeStamp.Value, parserResult.MinimumTimeStamp.Value);
 0137            }
 0138        }
 139        else
 30140        {
 30141            this.MinimumTimeStamp = parserResult.MinimumTimeStamp;
 30142        }
 143
 30144        if (this.MaximumTimeStamp.HasValue)
 0145        {
 0146            if (parserResult.MaximumTimeStamp.HasValue)
 0147            {
 0148                this.MaximumTimeStamp = Max(this.MaximumTimeStamp.Value, parserResult.MaximumTimeStamp.Value);
 0149            }
 0150        }
 151        else
 30152        {
 30153            this.MaximumTimeStamp = parserResult.MaximumTimeStamp;
 30154        }
 30155    }
 156
 157    /// <summary>
 158    /// Returns the minimum date.
 159    /// </summary>
 160    /// <param name="first">The first date.</param>
 161    /// <param name="second">The second date.</param>
 162    /// <returns>The minimum of the two dates.</returns>
 163    private static DateTime Min(DateTime first, DateTime second)
 0164    {
 0165        if (first < second)
 0166        {
 0167            return first;
 168        }
 169        else
 0170        {
 0171            return second;
 172        }
 0173    }
 174
 175    /// <summary>
 176    /// Returns the maximum date.
 177    /// </summary>
 178    /// <param name="first">The first date.</param>
 179    /// <param name="second">The second date.</param>
 180    /// <returns>The maximum of the two dates.</returns>
 181    private static DateTime Max(DateTime first, DateTime second)
 0182    {
 0183        if (first > second)
 0184        {
 0185            return first;
 186        }
 187        else
 0188        {
 0189            return second;
 190        }
 0191    }
 192}