< Summary

Information
Class: Elsa.Workflows.Helpers.Diff<T>
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Helpers/Diff.cs
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 57
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Added()100%11100%
get_Removed()100%11100%
get_Unchanged()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Helpers/Diff.cs

#LineLine coverage
 1namespace Elsa.Workflows.Helpers;
 2
 3/// <summary>
 4/// A utility that compares two collections and returns a set of added, removed and unchanged items.
 5/// </summary>
 6public class Diff<T>
 7{
 9598    internal Diff(ICollection<T> added, ICollection<T> removed, ICollection<T> unchanged)
 9    {
 95910        Added = added;
 95911        Removed = removed;
 95912        Unchanged = unchanged;
 95913    }
 14
 15    /// <summary>
 16    /// The added items.
 17    /// </summary>
 191718    public ICollection<T> Added { get; }
 19
 20    /// <summary>
 21    /// The removed items.
 22    /// </summary>
 191723    public ICollection<T> Removed { get; }
 24
 25    /// <summary>
 26    /// The unchanged items.
 27    /// </summary>
 95828    public ICollection<T> Unchanged { get; }
 29}
 30
 31/// <summary>
 32/// A factory class to construct new <see cref="Diff{T}"/> objects.
 33/// </summary>
 34public static class Diff
 35{
 36    /// <summary>
 37    /// Creates a new diff.
 38    /// </summary>
 39    public static Diff<T> From<T>(ICollection<T> added, ICollection<T> removed, ICollection<T> unchanged) => new(added, 
 40
 41    /// <summary>
 42    /// Returns an empty diff.
 43    /// </summary>
 44    public static Diff<T> Empty<T>() => new(Array.Empty<T>(), Array.Empty<T>(), Array.Empty<T>());
 45
 46    /// <summary>
 47    /// Create a diff between two sets.
 48    /// </summary>
 49    public static Diff<T> For<T>(ICollection<T> firstSet, ICollection<T> secondSet, IEqualityComparer<T>? comparer = def
 50    {
 51        var removed = firstSet.Except(secondSet, comparer).ToList();
 52        var added = secondSet.Except(firstSet, comparer).ToList();
 53        var unchanged = firstSet.Intersect(secondSet, comparer).ToList();
 54
 55        return new Diff<T>(added, removed, unchanged);
 56    }
 57}