<PackageReference Include="NUnit" Version="3.8.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; private CollectionTally.CollectionTallyResult _tallyResult; public override string DisplayName => "Equivalent"; public override string Description => "equivalent to " + MsgUtils.FormatValue(_expected); public CollectionEquivalentConstraint(IEnumerable expected) : base(expected) { _expected = expected; } protected override bool Matches(IEnumerable actual) { CollectionTally collectionTally = Tally(_expected); collectionTally.TryRemove(actual); _tallyResult = collectionTally.Result; if (_tallyResult.ExtraItems.Count == 0) return _tallyResult.MissingItems.Count == 0; return false; } public override ConstraintResult ApplyTo<TActual>(TActual actual) { IEnumerable enumerable = actual as IEnumerable; if (enumerable == null) throw new ArgumentException("The actual value must be an IEnumerable", "actual"); bool isSuccess = Matches(enumerable); return new CollectionEquivalentConstraintResult(this, _tallyResult, actual, isSuccess); } public CollectionEquivalentConstraint Using<TActual, TExpected>(Func<TActual, TExpected, bool> comparison) { Using(EqualityAdapter.For(comparison)); return this; } } }