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

PredicateConstraint<T>

public class PredicateConstraint<T> : Constraint
Predicate constraint wraps a Predicate in a constraint, returning success if the predicate is true.
using System; using System.Reflection; namespace NUnit.Framework.Constraints { public class PredicateConstraint<T> : Constraint { private readonly Predicate<T> predicate; public override string Description { get { string name = predicate.GetMethodInfo().Name; if (!name.StartsWith("<")) return "value matching " + name; return "value matching lambda expression"; } } public PredicateConstraint(Predicate<T> predicate) : base(Array.Empty<object>()) { this.predicate = predicate; } public override ConstraintResult ApplyTo<TActual>(TActual actual) { if (!(((object)actual) is T)) throw new ArgumentException("The actual value is not of type " + typeof(T).get_Name(), "actual"); return new ConstraintResult(this, actual, this.predicate((T)(object)actual)); } } }