| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using System.Linq; |
| | | 4 | | using DirectSight.Common; |
| | | 5 | | |
| | | 6 | | namespace DirectSight.Parser.Analysis; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Overall result of all assemblies. |
| | | 10 | | /// </summary> |
| | | 11 | | public class SummaryResult |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Initializes a new instance of the <see cref="SummaryResult" /> class. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="parserResult">The parser result.</param> |
| | | 17 | | public SummaryResult(ParserResult parserResult) |
| | 2 | 18 | | : this(parserResult.Assemblies, parserResult.ParserName, parserResult.SupportsBranchCoverage) |
| | 2 | 19 | | { |
| | 2 | 20 | | this.MinimumTimeStamp = parserResult.MinimumTimeStamp; |
| | 2 | 21 | | this.MaximumTimeStamp = parserResult.MaximumTimeStamp; |
| | 2 | 22 | | } |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Initializes a new instance of the <see cref="SummaryResult" /> class. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <param name="assemblies">The assemblies.</param> |
| | | 28 | | /// <param name="usedParser">The used parser.</param> |
| | | 29 | | /// <param name="supportsBranchCoverage">if set to <c>true</c> the used parser supports branch coverage.</param> |
| | 2 | 30 | | public SummaryResult( |
| | 2 | 31 | | IReadOnlyCollection<Assembly> assemblies, |
| | 2 | 32 | | string usedParser, bool supportsBranchCoverage) |
| | 2 | 33 | | { |
| | 2 | 34 | | this.Assemblies = assemblies ?? throw new ArgumentNullException(nameof(assemblies)); |
| | 2 | 35 | | this.UsedParser = usedParser ?? throw new ArgumentNullException(nameof(usedParser)); |
| | 2 | 36 | | this.SupportsBranchCoverage = supportsBranchCoverage; |
| | 2 | 37 | | } |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Gets the assemblies. |
| | | 41 | | /// </summary> |
| | | 42 | | /// <value> |
| | | 43 | | /// The assemblies. |
| | | 44 | | /// </value> |
| | 174 | 45 | | public IReadOnlyCollection<Assembly> Assemblies { get; } |
| | | 46 | | |
| | | 47 | | /// <summary> |
| | | 48 | | /// Gets the used parser. |
| | | 49 | | /// </summary> |
| | | 50 | | /// <value> |
| | | 51 | | /// The used parser. |
| | | 52 | | /// </value> |
| | 4 | 53 | | public string UsedParser { get; } |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets a value indicating whether the used parser supports branch coverage. |
| | | 57 | | /// </summary> |
| | | 58 | | /// <value> |
| | | 59 | | /// <c>true</c> if used parser supports branch coverage; otherwise, <c>false</c>. |
| | | 60 | | /// </value> |
| | 42 | 61 | | public bool SupportsBranchCoverage { get; } |
| | | 62 | | |
| | | 63 | | /// <summary> |
| | | 64 | | /// Gets the timestamp on which the coverage report was generated. |
| | | 65 | | /// </summary> |
| | 2 | 66 | | public DateTime? MinimumTimeStamp { get; } |
| | | 67 | | |
| | | 68 | | /// <summary> |
| | | 69 | | /// Gets the timestamp on which the coverage report was generated. |
| | | 70 | | /// </summary> |
| | 2 | 71 | | public DateTime? MaximumTimeStamp { get; } |
| | | 72 | | |
| | | 73 | | /// <summary> |
| | | 74 | | /// Gets the number of covered lines. |
| | | 75 | | /// </summary> |
| | | 76 | | /// <value>The covered lines.</value> |
| | 52 | 77 | | public int CoveredLines => this.Assemblies.SafeSum(a => a.CoveredLines); |
| | | 78 | | |
| | | 79 | | /// <summary> |
| | | 80 | | /// Gets the number of coverable lines. |
| | | 81 | | /// </summary> |
| | | 82 | | /// <value>The coverable lines.</value> |
| | 84 | 83 | | public int CoverableLines => this.Assemblies.SafeSum(a => a.CoverableLines); |
| | | 84 | | |
| | | 85 | | /// <summary> |
| | | 86 | | /// Gets the number of total lines. |
| | | 87 | | /// </summary> |
| | | 88 | | /// <value>The total lines.</value> |
| | | 89 | | public int? TotalLines |
| | | 90 | | { |
| | | 91 | | get |
| | 4 | 92 | | { |
| | 4 | 93 | | var processedFiles = new HashSet<string>(); |
| | 4 | 94 | | int? result = null; |
| | | 95 | | |
| | 20 | 96 | | foreach (var assembly in this.Assemblies) |
| | 4 | 97 | | { |
| | 156 | 98 | | foreach (var clazz in assembly.Classes) |
| | 72 | 99 | | { |
| | 360 | 100 | | foreach (var file in clazz.Files) |
| | 72 | 101 | | { |
| | 72 | 102 | | if (!processedFiles.Contains(file.Path) && file.TotalLines.HasValue) |
| | 60 | 103 | | { |
| | 60 | 104 | | processedFiles.Add(file.Path); |
| | 60 | 105 | | result = result.HasValue ? result + file.TotalLines : file.TotalLines; |
| | 60 | 106 | | } |
| | 72 | 107 | | } |
| | 72 | 108 | | } |
| | 4 | 109 | | } |
| | | 110 | | |
| | 4 | 111 | | return result; |
| | 4 | 112 | | } |
| | | 113 | | } |
| | | 114 | | |
| | | 115 | | /// <summary> |
| | | 116 | | /// Gets the coverage quota. |
| | | 117 | | /// </summary> |
| | | 118 | | /// <value>The coverage quota.</value> |
| | 16 | 119 | | public decimal? CoverageQuota => (this.CoverableLines == 0) ? (decimal?)null : MathExtensions.CalculatePercentage(th |
| | | 120 | | |
| | | 121 | | /// <summary> |
| | | 122 | | /// Gets the number of covered branches. |
| | | 123 | | /// </summary> |
| | | 124 | | /// <value> |
| | | 125 | | /// The number of covered branches. |
| | | 126 | | /// </value> |
| | 52 | 127 | | public int? CoveredBranches => this.Assemblies.SafeSum(f => f.CoveredBranches); |
| | | 128 | | |
| | | 129 | | /// <summary> |
| | | 130 | | /// Gets the number of total branches. |
| | | 131 | | /// </summary> |
| | | 132 | | /// <value> |
| | | 133 | | /// The number of total branches. |
| | | 134 | | /// </value> |
| | 84 | 135 | | public int? TotalBranches => this.Assemblies.SafeSum(f => f.TotalBranches); |
| | | 136 | | |
| | | 137 | | /// <summary> |
| | | 138 | | /// Gets the branch coverage quota. |
| | | 139 | | /// </summary> |
| | | 140 | | /// <value>The branch coverage quota.</value> |
| | 16 | 141 | | public decimal? BranchCoverageQuota => (this.TotalBranches == 0) ? (decimal?)null : MathExtensions.CalculatePercenta |
| | | 142 | | |
| | | 143 | | /// <summary> |
| | | 144 | | /// Gets the number of covered code elements. |
| | | 145 | | /// </summary> |
| | | 146 | | /// <value> |
| | | 147 | | /// The number of covered code elements. |
| | | 148 | | /// </value> |
| | 12 | 149 | | public int CoveredCodeElements => this.Assemblies.SafeSum(f => f.CoveredCodeElements); |
| | | 150 | | |
| | | 151 | | /// <summary> |
| | | 152 | | /// Gets the number of fully covered code elements. |
| | | 153 | | /// </summary> |
| | | 154 | | /// <value> |
| | | 155 | | /// The number of fully covered code elements. |
| | | 156 | | /// </value> |
| | 12 | 157 | | public int FullCoveredCodeElements => this.Assemblies.SafeSum(f => f.FullCoveredCodeElements); |
| | | 158 | | |
| | | 159 | | /// <summary> |
| | | 160 | | /// Gets the number of total code elements. |
| | | 161 | | /// </summary> |
| | | 162 | | /// <value> |
| | | 163 | | /// The number of total code elements. |
| | | 164 | | /// </value> |
| | 36 | 165 | | public int TotalCodeElements => this.Assemblies.SafeSum(f => f.TotalCodeElements); |
| | | 166 | | |
| | | 167 | | /// <summary> |
| | | 168 | | /// Gets the code elements coverage quota. |
| | | 169 | | /// </summary> |
| | | 170 | | /// <value>The code elements coverage quota.</value> |
| | 4 | 171 | | public decimal? CodeElementCoverageQuota => (this.TotalCodeElements == 0) ? (decimal?)null : MathExtensions.Calculat |
| | | 172 | | |
| | | 173 | | /// <summary> |
| | | 174 | | /// Gets the full code elements coverage quota. |
| | | 175 | | /// </summary> |
| | | 176 | | /// <value>The full code elements coverage quota.</value> |
| | 4 | 177 | | public decimal? FullCodeElementCoverageQuota => (this.TotalCodeElements == 0) ? (decimal?)null : MathExtensions.Calc |
| | | 178 | | |
| | | 179 | | /// <summary> |
| | | 180 | | /// Get the coverage date(s) based on the minimum and maximum timestamp. |
| | | 181 | | /// </summary> |
| | | 182 | | /// <returns> The coverage date(s).</returns> |
| | | 183 | | public string CoverageDate() |
| | 0 | 184 | | { |
| | 0 | 185 | | string value = null; |
| | | 186 | | |
| | 0 | 187 | | if (this.MinimumTimeStamp.HasValue) |
| | 0 | 188 | | { |
| | 0 | 189 | | value = $"{this.MinimumTimeStamp.Value.ToShortDateString()} - {this.MinimumTimeStamp.Value.ToLongTimeString( |
| | | 190 | | |
| | 0 | 191 | | if (this.MaximumTimeStamp.HasValue |
| | 0 | 192 | | && !this.MinimumTimeStamp.Value.Equals(this.MaximumTimeStamp.Value)) |
| | 0 | 193 | | { |
| | 0 | 194 | | value += $" - {this.MaximumTimeStamp.Value.ToShortDateString()} - {this.MaximumTimeStamp.Value.ToLongTim |
| | 0 | 195 | | } |
| | 0 | 196 | | } |
| | 0 | 197 | | else if (this.MaximumTimeStamp.HasValue) |
| | 0 | 198 | | { |
| | 0 | 199 | | value = $"{this.MaximumTimeStamp.Value.ToShortDateString()} - {this.MaximumTimeStamp.Value.ToLongTimeString( |
| | 0 | 200 | | } |
| | | 201 | | |
| | 0 | 202 | | return value; |
| | 0 | 203 | | } |
| | | 204 | | } |