< Summary

Information
Class: DotNetApiDiff.Models.ApiComparison
Assembly: DotNetApiDiff
File(s): /home/runner/work/dotnet-api-diff/dotnet-api-diff/src/DotNetApiDiff/Models/ApiComparison.cs
Line coverage
100%
Covered lines: 53
Uncovered lines: 0
Coverable lines: 53
Total lines: 131
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Additions()100%11100%
get_Removals()100%11100%
get_Modifications()100%11100%
get_Excluded()100%11100%
get_Summary()100%11100%
get_InvalidMessage()100%11100%
get_AllChanges()100%11100%
get_HasBreakingChanges()100%11100%
get_TotalChanges()100%11100%
get_BreakingChangesCount()100%11100%
IsValid()100%1212100%
UpdateSummary()100%11100%

File(s)

/home/runner/work/dotnet-api-diff/dotnet-api-diff/src/DotNetApiDiff/Models/ApiComparison.cs

#LineLine coverage
 1// Copyright DotNet API Diff Project Contributors - SPDX Identifier: MIT
 2namespace DotNetApiDiff.Models;
 3
 4/// <summary>
 5/// Represents the complete comparison result between two API surfaces
 6/// </summary>
 7public class ApiComparison
 8{
 9    /// <summary>
 10    /// List of API members that were added
 11    /// </summary>
 9712    public List<ApiChange> Additions { get; set; } = new List<ApiChange>();
 13
 14    /// <summary>
 15    /// List of API members that were removed
 16    /// </summary>
 9417    public List<ApiChange> Removals { get; set; } = new List<ApiChange>();
 18
 19    /// <summary>
 20    /// List of API members that were modified
 21    /// </summary>
 8822    public List<ApiChange> Modifications { get; set; } = new List<ApiChange>();
 23
 24    /// <summary>
 25    /// List of API members that were intentionally excluded
 26    /// </summary>
 8127    public List<ApiChange> Excluded { get; set; } = new List<ApiChange>();
 28
 29    /// <summary>
 30    /// Summary statistics of the comparison
 31    /// </summary>
 4732    public ComparisonSummary Summary { get; set; } = new ComparisonSummary();
 33
 34    /// <summary>
 35    /// Gets the validation error message if the comparison is invalid, empty if valid
 36    /// </summary>
 4637    public string InvalidMessage { get; private set; } = string.Empty;
 38
 39    /// <summary>
 40    /// Gets all changes as a single collection
 41    /// </summary>
 42    public IEnumerable<ApiChange> AllChanges
 43    {
 44        get
 3245        {
 3246            return Additions.Concat(Removals).Concat(Modifications).Concat(Excluded);
 3247        }
 48    }
 49
 50    /// <summary>
 51    /// Gets whether any breaking changes were detected
 52    /// </summary>
 1853    public bool HasBreakingChanges => AllChanges.Any(c => c.IsBreakingChange);
 54
 55    /// <summary>
 56    /// Gets the total number of changes (excluding excluded items)
 57    /// </summary>
 358    public int TotalChanges => Additions.Count + Removals.Count + Modifications.Count;
 59
 60    /// <summary>
 61    /// Gets the total number of breaking changes
 62    /// </summary>
 2363    public int BreakingChangesCount => AllChanges.Count(c => c.IsBreakingChange);
 64
 65    /// <summary>
 66    /// Validates the ApiComparison instance
 67    /// </summary>
 68    /// <returns>True if valid, false otherwise</returns>
 69    public bool IsValid()
 1270    {
 71        // Clear any previous validation message
 1272        InvalidMessage = string.Empty;
 73
 1274        var errors = new List<string>();
 75
 76        // Validate all changes
 1277        var allChanges = AllChanges.ToList();
 2578        var invalidChanges = allChanges.Where(c => !c.IsValid()).ToList();
 1279        if (invalidChanges.Any())
 580        {
 1081            errors.Add($"Found {invalidChanges.Count} invalid change(s): {string.Join(", ", invalidChanges.Select(c => $
 582        }
 83
 84        // Validate that additions only contain Added changes
 1885        var wrongAdditions = Additions.Where(c => c.Type != ChangeType.Added).ToList();
 1286        if (wrongAdditions.Any())
 187        {
 288            errors.Add($"Additions collection contains {wrongAdditions.Count} change(s) with wrong type: {string.Join(",
 189        }
 90
 91        // Validate that removals only contain Removed changes
 1792        var wrongRemovals = Removals.Where(c => c.Type != ChangeType.Removed).ToList();
 1293        if (wrongRemovals.Any())
 194        {
 295            errors.Add($"Removals collection contains {wrongRemovals.Count} change(s) with wrong type: {string.Join(", "
 196        }
 97
 98        // Validate that modifications only contain Modified changes
 1399        var wrongModifications = Modifications.Where(c => c.Type != ChangeType.Modified).ToList();
 12100        if (wrongModifications.Any())
 1101        {
 2102            errors.Add($"Modifications collection contains {wrongModifications.Count} change(s) with wrong type: {string
 1103        }
 104
 105        // Validate that excluded only contain Excluded changes
 13106        var wrongExcluded = Excluded.Where(c => c.Type != ChangeType.Excluded).ToList();
 12107        if (wrongExcluded.Any())
 1108        {
 2109            errors.Add($"Excluded collection contains {wrongExcluded.Count} change(s) with wrong type: {string.Join(", "
 1110        }
 111
 12112        if (errors.Count > 0)
 6113        {
 6114            InvalidMessage = string.Join("; ", errors);
 6115            return false;
 116        }
 117
 6118        return true;
 12119    }
 120
 121    /// <summary>
 122    /// Updates the summary statistics based on current changes
 123    /// </summary>
 124    public void UpdateSummary()
 2125    {
 2126        Summary.AddedCount = Additions.Count;
 2127        Summary.RemovedCount = Removals.Count;
 2128        Summary.ModifiedCount = Modifications.Count;
 2129        Summary.BreakingChangesCount = BreakingChangesCount;
 2130    }
 131}