<PackageReference Include="NUnit" Version="3.2.1" />

CollectionEquivalentConstraint

CollectionEquivalentConstraint is used to determine whether two collections are equivalent.
using System; using System.Collections; namespace NUnit.Framework.Constraints { public class CollectionEquivalentConstraint : CollectionItemsEqualConstraint { private readonly IEnumerable expected; public override string Description => "equivalent to " + MsgUtils.FormatValue(expected); public CollectionEquivalentConstraint(IEnumerable expected) : base(expected) { this.expected = expected; base.DisplayName = "Equivalent"; } protected override bool Matches(IEnumerable actual) { if (expected is ICollection && actual is ICollection && ((ICollection)actual).Count != ((ICollection)expected).Count) return false; CollectionTally collectionTally = Tally(expected); if (collectionTally.TryRemove(actual)) return collectionTally.Count == 0; return false; } public CollectionEquivalentConstraint Using<TActual, TExpected>(Func<TActual, TExpected, bool> comparison) { Using(EqualityAdapter.For(comparison)); return this; } } }