< 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
83%
Covered lines: 30
Uncovered lines: 6
Coverable lines: 36
Total lines: 110
Line coverage: 83.3%
Branch coverage
70%
Covered branches: 7
Total branches: 10
Branch coverage: 70%
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_AllChanges()100%11100%
get_HasBreakingChanges()100%11100%
get_TotalChanges()100%11100%
get_BreakingChangesCount()100%11100%
IsValid()70%131068.42%
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>
 9212    public List<ApiChange> Additions { get; set; } = new List<ApiChange>();
 13
 14    /// <summary>
 15    /// List of API members that were removed
 16    /// </summary>
 8917    public List<ApiChange> Removals { get; set; } = new List<ApiChange>();
 18
 19    /// <summary>
 20    /// List of API members that were modified
 21    /// </summary>
 8322    public List<ApiChange> Modifications { get; set; } = new List<ApiChange>();
 23
 24    /// <summary>
 25    /// List of API members that were intentionally excluded
 26    /// </summary>
 7527    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 all changes as a single collection
 36    /// </summary>
 37    public IEnumerable<ApiChange> AllChanges
 38    {
 39        get
 3240        {
 3241            return Additions.Concat(Removals).Concat(Modifications).Concat(Excluded);
 3242        }
 43    }
 44
 45    /// <summary>
 46    /// Gets whether any breaking changes were detected
 47    /// </summary>
 1848    public bool HasBreakingChanges => AllChanges.Any(c => c.IsBreakingChange);
 49
 50    /// <summary>
 51    /// Gets the total number of changes (excluding excluded items)
 52    /// </summary>
 353    public int TotalChanges => Additions.Count + Removals.Count + Modifications.Count;
 54
 55    /// <summary>
 56    /// Gets the total number of breaking changes
 57    /// </summary>
 2358    public int BreakingChangesCount => AllChanges.Count(c => c.IsBreakingChange);
 59
 60    /// <summary>
 61    /// Validates the ApiComparison instance
 62    /// </summary>
 63    /// <returns>True if valid, false otherwise</returns>
 64    public bool IsValid()
 1265    {
 66        // Validate all changes
 1267        var allChanges = AllChanges.ToList();
 2568        if (allChanges.Any(c => !c.IsValid()))
 569        {
 570            return false;
 71        }
 72
 73        // Validate that additions only contain Added changes
 1074        if (Additions.Any(c => c.Type != ChangeType.Added))
 075        {
 076            return false;
 77        }
 78
 79        // Validate that removals only contain Removed changes
 1180        if (Removals.Any(c => c.Type != ChangeType.Removed))
 081        {
 082            return false;
 83        }
 84
 85        // Validate that modifications only contain Modified changes
 886        if (Modifications.Any(c => c.Type != ChangeType.Modified))
 187        {
 188            return false;
 89        }
 90
 91        // Validate that excluded only contain Excluded changes
 692        if (Excluded.Any(c => c.Type != ChangeType.Excluded))
 093        {
 094            return false;
 95        }
 96
 697        return true;
 1298    }
 99
 100    /// <summary>
 101    /// Updates the summary statistics based on current changes
 102    /// </summary>
 103    public void UpdateSummary()
 2104    {
 2105        Summary.AddedCount = Additions.Count;
 2106        Summary.RemovedCount = Removals.Count;
 2107        Summary.ModifiedCount = Modifications.Count;
 2108        Summary.BreakingChangesCount = BreakingChangesCount;
 2109    }
 110}