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

ConstraintExpression

public class ConstraintExpression
ConstraintExpression represents a compound constraint in the process of being constructed from a series of syntactic elements. Individual elements are appended to the expression as they are reorganized. When a constraint is appended, it is returned as the value of the operation so that modifiers may be applied. However, any partially built expression is attached to the constraint for later resolution. When an operator is appended, the partial expression is returned. If it's a self-resolving operator, then a ResolvableConstraintExpression is returned.
using System; using System.Collections; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; namespace NUnit.Framework.Constraints { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public class ConstraintExpression { protected readonly ConstraintBuilder builder; public ConstraintExpression Not => Append((ConstraintOperator)new NotOperator()); public ConstraintExpression No => Append((ConstraintOperator)new NotOperator()); public ConstraintExpression All => Append((ConstraintOperator)new AllOperator()); public ConstraintExpression Some => Append((ConstraintOperator)new SomeOperator()); public ConstraintExpression None => Append((ConstraintOperator)new NoneOperator()); public ItemsConstraintExpression One { get { builder.Append(new ExactCountOperator(1)); return new ItemsConstraintExpression(builder); } } public ResolvableConstraintExpression Length => Property("Length"); public ResolvableConstraintExpression Count => Property("Count"); public ResolvableConstraintExpression Message => Property("Message"); public ResolvableConstraintExpression InnerException => Property("InnerException"); public ConstraintExpression With => Append((ConstraintOperator)new WithOperator()); public NullConstraint Null => Append(new NullConstraint()); public DefaultConstraint Default => Append(new DefaultConstraint()); public TrueConstraint True => Append(new TrueConstraint()); public FalseConstraint False => Append(new FalseConstraint()); public GreaterThanConstraint Positive => Append(new GreaterThanConstraint(0)); public LessThanConstraint Negative => Append(new LessThanConstraint(0)); public EqualConstraint Zero => Append(new EqualConstraint(0)); public NaNConstraint NaN => Append(new NaNConstraint()); public EmptyConstraint Empty => Append(new EmptyConstraint()); public WhiteSpaceConstraint WhiteSpace => Append(new WhiteSpaceConstraint()); public UniqueItemsConstraint Unique => Append(new UniqueItemsConstraint()); public XmlSerializableConstraint XmlSerializable => Append(new XmlSerializableConstraint()); public CollectionOrderedConstraint Ordered => Append(new CollectionOrderedConstraint()); public Constraint Exist => Append(new FileOrDirectoryExistsConstraint()); public ConstraintExpression() : this(new ConstraintBuilder()) { } public ConstraintExpression(ConstraintBuilder builder) { Guard.ArgumentNotNull(builder, "builder"); this.builder = builder; } public override string ToString() { return builder.Resolve().ToString(); } public ConstraintExpression Append(ConstraintOperator op) { builder.Append(op); return this; } public ResolvableConstraintExpression Append(SelfResolvingOperator op) { builder.Append(op); return new ResolvableConstraintExpression(builder); } public Constraint Append(Constraint constraint) { builder.Append(constraint); return constraint; } public T Append<[System.Runtime.CompilerServices.Nullable(0)] T>(T constraint) where T : Constraint { builder.Append(constraint); return constraint; } public ItemsConstraintExpression Exactly(int expectedCount) { builder.Append(new ExactCountOperator(expectedCount)); return new ItemsConstraintExpression(builder); } public ResolvableConstraintExpression Property(string name) { return Append((SelfResolvingOperator)new PropOperator(name)); } public ResolvableConstraintExpression Attribute(Type expectedType) { return Append((SelfResolvingOperator)new AttributeOperator(expectedType)); } public ResolvableConstraintExpression Attribute<[System.Runtime.CompilerServices.Nullable(2)] TExpected>() { return Attribute(typeof(TExpected)); } public Constraint Matches(IResolveConstraint constraint) { return Append((Constraint)constraint.Resolve()); } public Constraint Matches<[System.Runtime.CompilerServices.Nullable(2)] TActual>(Predicate<TActual> predicate) { return Append(new PredicateConstraint<TActual>(predicate)); } public EqualConstraint EqualTo([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Append(new EqualConstraint(expected)); } public SameAsConstraint SameAs([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Append(new SameAsConstraint(expected)); } public GreaterThanConstraint GreaterThan(object expected) { return Append(new GreaterThanConstraint(expected)); } public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected) { return Append(new GreaterThanOrEqualConstraint(expected)); } public GreaterThanOrEqualConstraint AtLeast(object expected) { return Append(new GreaterThanOrEqualConstraint(expected)); } public LessThanConstraint LessThan(object expected) { return Append(new LessThanConstraint(expected)); } public LessThanOrEqualConstraint LessThanOrEqualTo(object expected) { return Append(new LessThanOrEqualConstraint(expected)); } public LessThanOrEqualConstraint AtMost(object expected) { return Append(new LessThanOrEqualConstraint(expected)); } public ExactTypeConstraint TypeOf(Type expectedType) { return Append(new ExactTypeConstraint(expectedType)); } public ExactTypeConstraint TypeOf<[System.Runtime.CompilerServices.Nullable(2)] TExpected>() { return Append(new ExactTypeConstraint(typeof(TExpected))); } public InstanceOfTypeConstraint InstanceOf(Type expectedType) { return Append(new InstanceOfTypeConstraint(expectedType)); } public InstanceOfTypeConstraint InstanceOf<[System.Runtime.CompilerServices.Nullable(2)] TExpected>() { return Append(new InstanceOfTypeConstraint(typeof(TExpected))); } public AssignableFromConstraint AssignableFrom(Type expectedType) { return Append(new AssignableFromConstraint(expectedType)); } public AssignableFromConstraint AssignableFrom<[System.Runtime.CompilerServices.Nullable(2)] TExpected>() { return Append(new AssignableFromConstraint(typeof(TExpected))); } public AssignableToConstraint AssignableTo(Type expectedType) { return Append(new AssignableToConstraint(expectedType)); } public AssignableToConstraint AssignableTo<[System.Runtime.CompilerServices.Nullable(2)] TExpected>() { return Append(new AssignableToConstraint(typeof(TExpected))); } public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected) { return Append(new CollectionEquivalentConstraint(expected)); } public CollectionSubsetConstraint SubsetOf(IEnumerable expected) { return Append(new CollectionSubsetConstraint(expected)); } public CollectionSupersetConstraint SupersetOf(IEnumerable expected) { return Append(new CollectionSupersetConstraint(expected)); } public SomeItemsConstraint Member([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Append(new SomeItemsConstraint(new EqualConstraint(expected))); } public SomeItemsConstraint Contains([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Append(new SomeItemsConstraint(new EqualConstraint(expected))); } public ContainsConstraint Contains([System.Runtime.CompilerServices.Nullable(2)] string expected) { return Append(new ContainsConstraint(expected)); } public SomeItemsConstraint Contain([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Contains(expected); } public ContainsConstraint Contain([System.Runtime.CompilerServices.Nullable(2)] string expected) { return Contains(expected); } public DictionaryContainsKeyConstraint ContainKey(object expected) { return Append(new DictionaryContainsKeyConstraint(expected)); } public DictionaryContainsValueConstraint ContainValue([System.Runtime.CompilerServices.Nullable(2)] object expected) { return Append(new DictionaryContainsValueConstraint(expected)); } public StartsWithConstraint StartWith(string expected) { return Append(new StartsWithConstraint(expected)); } public StartsWithConstraint StartsWith(string expected) { return Append(new StartsWithConstraint(expected)); } public EndsWithConstraint EndWith(string expected) { return Append(new EndsWithConstraint(expected)); } public EndsWithConstraint EndsWith(string expected) { return Append(new EndsWithConstraint(expected)); } public RegexConstraint Match([StringSyntax("Regex")] string pattern) { return Append(new RegexConstraint(pattern)); } public RegexConstraint Match(Regex regex) { return Append(new RegexConstraint(regex)); } public RegexConstraint Matches([StringSyntax("Regex")] string pattern) { return Append(new RegexConstraint(pattern)); } public RegexConstraint Matches(Regex regex) { return Append(new RegexConstraint(regex)); } public SamePathConstraint SamePath(string expected) { return Append(new SamePathConstraint(expected)); } public SubPathConstraint SubPathOf(string expected) { return Append(new SubPathConstraint(expected)); } public SamePathOrUnderConstraint SamePathOrUnder(string expected) { return Append(new SamePathOrUnderConstraint(expected)); } public RangeConstraint InRange(object from, object to) { return Append(new RangeConstraint(from, to)); } public AnyOfConstraint AnyOf([System.Runtime.CompilerServices.Nullable(2)] params object[] expected) { if (expected == null) expected = new object[1]; return Append(new AnyOfConstraint(expected)); } public AnyOfConstraint AnyOf(ICollection expected) { return Append(new AnyOfConstraint(expected)); } public ConstraintExpression ItemAt(params object[] indexArgs) { return Append((ConstraintOperator)new IndexerOperator(indexArgs)); } } }