CollectionSupersetConstraint
CollectionSupersetConstraint is used to determine whether
one collection is a superset of another
using System;
using System.Collections;
namespace NUnit.Framework.Constraints
{
public class CollectionSupersetConstraint : CollectionItemsEqualConstraint
{
private IEnumerable _expected;
public override string DisplayName => "SupersetOf";
public override string Description => "superset of " + MsgUtils.FormatValue(_expected);
public CollectionSupersetConstraint(IEnumerable expected)
: base(expected)
{
_expected = expected;
}
protected override bool Matches(IEnumerable actual)
{
CollectionTally collectionTally = Tally(actual);
collectionTally.TryRemove(_expected);
return collectionTally.Result.ExtraItems.Count == 0;
}
public CollectionSupersetConstraint Using<TSupersetType, TSubsetType>(Func<TSupersetType, TSubsetType, bool> comparison)
{
Func<TSubsetType, TSupersetType, bool> comparison2 = (TSubsetType actual, TSupersetType expected) => comparison(expected, actual);
Using(EqualityAdapter.For(comparison2));
return this;
}
}
}