NoItemConstraint
NoItemConstraint applies another constraint to each
item in a collection, failing if any of them succeeds.
using NUnit.Framework.Internal;
using System.Collections;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class NoItemConstraint : PrefixConstraint
{
public override string DisplayName => "None";
public NoItemConstraint(IConstraint itemConstraint)
: base(itemConstraint, "no item")
{
}
public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(TActual actual)
{
IEnumerable enumerable = ConstraintUtils.RequireActual<IEnumerable>(actual, "actual", false);
int num = 0;
foreach (object item in enumerable) {
if (base.BaseConstraint.ApplyTo(item).IsSuccess)
return new EachItemConstraintResult(this, actual, item, num);
num++;
}
return new ConstraintResult(this, actual, ConstraintStatus.Success);
}
}
}