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