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

CollectionContainsConstraint

CollectionContainsConstraint is used to test whether a collection contains an expected object as a member.
using System; using System.Collections; namespace NUnit.Framework.Constraints { public class CollectionContainsConstraint : CollectionItemsEqualConstraint { public override string Description => "collection containing " + MsgUtils.FormatValue(Expected); protected object Expected { get; set; } public CollectionContainsConstraint(object expected) : base(expected) { Expected = expected; base.DisplayName = "Contains"; } protected override bool Matches(IEnumerable actual) { foreach (object item in actual) { if (ItemsEqual(item, Expected)) return true; } return false; } public CollectionContainsConstraint Using<TCollectionType, TMemberType>(Func<TCollectionType, TMemberType, bool> comparison) { Func<TMemberType, TCollectionType, bool> comparison2 = (TMemberType actual, TCollectionType expected) => comparison(expected, actual); Using(EqualityAdapter.For(comparison2)); return this; } } }