Class ConstraintExpression
- Namespace
- NUnit.Framework.Constraints
- Assembly
- nunit.framework.dll
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.
public class ConstraintExpression
- Inheritance
-
ConstraintExpression
- Derived
- Inherited Members
Constructors
ConstraintExpression()
Initializes a new instance of the ConstraintExpression class.
public ConstraintExpression()
ConstraintExpression(ConstraintBuilder)
Initializes a new instance of the ConstraintExpression class passing in a ConstraintBuilder, which may be pre-populated.
public ConstraintExpression(ConstraintBuilder builder)
Parameters
builder
ConstraintBuilderThe builder.
Fields
builder
The ConstraintBuilder holding the elements recognized so far
protected readonly ConstraintBuilder builder
Field Value
Properties
All
Returns a ConstraintExpression, which will apply the following constraint to all members of a collection, succeeding if all of them succeed.
public ConstraintExpression All { get; }
Property Value
Count
Returns a new ConstraintExpression, which will apply the following constraint to the Count property of the object being tested.
public ResolvableConstraintExpression Count { get; }
Property Value
Default
Returns a constraint that tests for default value
public DefaultConstraint Default { get; }
Property Value
Empty
Returns a constraint that tests for empty
public EmptyConstraint Empty { get; }
Property Value
Exist
Returns a constraint that succeeds if the value is a file or directory and it exists.
public Constraint Exist { get; }
Property Value
False
Returns a constraint that tests for False
public FalseConstraint False { get; }
Property Value
InnerException
Returns a new ConstraintExpression, which will apply the following constraint to the InnerException property of the object being tested.
public ResolvableConstraintExpression InnerException { get; }
Property Value
Length
Returns a new ConstraintExpression, which will apply the following constraint to the Length property of the object being tested.
public ResolvableConstraintExpression Length { get; }
Property Value
Message
Returns a new ConstraintExpression, which will apply the following constraint to the Message property of the object being tested.
public ResolvableConstraintExpression Message { get; }
Property Value
NaN
Returns a constraint that tests for NaN
public NaNConstraint NaN { get; }
Property Value
Negative
Returns a constraint that tests for a negative value
public LessThanConstraint Negative { get; }
Property Value
No
Returns a ConstraintExpression that negates any following constraint.
public ConstraintExpression No { get; }
Property Value
None
Returns a ConstraintExpression, which will apply the following constraint to all members of a collection, succeeding if all of them fail.
public ConstraintExpression None { get; }
Property Value
Not
Returns a ConstraintExpression that negates any following constraint.
public ConstraintExpression Not { get; }
Property Value
Null
Returns a constraint that tests for null
public NullConstraint Null { get; }
Property Value
One
Returns a ItemsConstraintExpression, which will apply the following constraint to a collection of length one, succeeding only if exactly one of them succeeds.
public ItemsConstraintExpression One { get; }
Property Value
Ordered
Returns a constraint that tests whether a collection is ordered
public CollectionOrderedConstraint Ordered { get; }
Property Value
Positive
Returns a constraint that tests for a positive value
public GreaterThanConstraint Positive { get; }
Property Value
Some
Returns a ConstraintExpression, which will apply the following constraint to all members of a collection, succeeding if at least one of them succeeds.
public ConstraintExpression Some { get; }
Property Value
True
Returns a constraint that tests for True
public TrueConstraint True { get; }
Property Value
Unique
Returns a constraint that tests whether a collection contains all unique items.
public UniqueItemsConstraint Unique { get; }
Property Value
With
With is currently a NOP - reserved for future use.
public ConstraintExpression With { get; }
Property Value
XmlSerializable
Returns a constraint that tests whether an object graph is serializable in XML format.
public XmlSerializableConstraint XmlSerializable { get; }
Property Value
Zero
Returns a constraint that tests if item is equal to zero
public EqualConstraint Zero { get; }
Property Value
Methods
AnyOf(ICollection)
Returns a constraint that tests if an item is equal to any of expected values
public AnyOfConstraint AnyOf(ICollection expected)
Parameters
expected
ICollectionExpected values
Returns
AnyOf(params object?[]?)
Returns a constraint that tests if an item is equal to any of parameters
public AnyOfConstraint AnyOf(params object?[]? expected)
Parameters
expected
object[]Expected values
Returns
Append(Constraint)
Appends a constraint to the expression and returns that constraint, which is associated with the current state of the expression being built. Note that the constraint is not reduced at this time. For example, if there is a NotOperator on the stack we don't reduce and return a NotConstraint. The original constraint must be returned because it may support modifiers that are yet to be applied.
public Constraint Append(Constraint constraint)
Parameters
constraint
Constraint
Returns
Append(ConstraintOperator)
Appends an operator to the expression and returns the resulting expression itself.
public ConstraintExpression Append(ConstraintOperator op)
Parameters
Returns
Append(SelfResolvingOperator)
Appends a self-resolving operator to the expression and returns a new ResolvableConstraintExpression.
public ResolvableConstraintExpression Append(SelfResolvingOperator op)
Parameters
Returns
AssignableFrom(Type)
Returns a constraint that tests whether the actual value is assignable from the type supplied as an argument.
public AssignableFromConstraint AssignableFrom(Type expectedType)
Parameters
expectedType
Type
Returns
AssignableFrom<TExpected>()
Returns a constraint that tests whether the actual value is assignable from the type supplied as an argument.
public AssignableFromConstraint AssignableFrom<TExpected>()
Returns
Type Parameters
TExpected
AssignableTo(Type)
Returns a constraint that tests whether the actual value is assignable from the type supplied as an argument.
public AssignableToConstraint AssignableTo(Type expectedType)
Parameters
expectedType
Type
Returns
AssignableTo<TExpected>()
Returns a constraint that tests whether the actual value is assignable from the type supplied as an argument.
public AssignableToConstraint AssignableTo<TExpected>()
Returns
Type Parameters
TExpected
AtLeast(object)
Returns a constraint that tests whether the actual value is greater than or equal to the supplied argument
public GreaterThanOrEqualConstraint AtLeast(object expected)
Parameters
expected
object
Returns
AtMost(object)
Returns a constraint that tests whether the actual value is less than or equal to the supplied argument
public LessThanOrEqualConstraint AtMost(object expected)
Parameters
expected
object
Returns
Attribute(Type)
Returns a new AttributeConstraint checking for the presence of a particular attribute on an object.
public ResolvableConstraintExpression Attribute(Type expectedType)
Parameters
expectedType
Type
Returns
Attribute<TExpected>()
Returns a new AttributeConstraint checking for the presence of a particular attribute on an object.
public ResolvableConstraintExpression Attribute<TExpected>()
Returns
Type Parameters
TExpected
Contain(object?)
Returns a new SomeItemsConstraint checking for the presence of a particular object in the collection.
public SomeItemsConstraint Contain(object? expected)
Parameters
expected
object
Returns
Contain(string?)
Returns a new ContainsConstraint. This constraint will, in turn, make use of the appropriate second-level constraint, depending on the type of the actual argument. This overload is only used if the item sought is a string, since any other type implies that we are looking for a collection member.
public ContainsConstraint Contain(string? expected)
Parameters
expected
string
Returns
ContainKey(object)
Returns a new DictionaryContainsKeyConstraint checking for the presence of a particular key in the Dictionary key collection.
public DictionaryContainsKeyConstraint ContainKey(object expected)
Parameters
expected
objectThe key to be matched in the Dictionary key collection
Returns
ContainValue(object)
Returns a new DictionaryContainsValueConstraint checking for the presence of a particular value in the Dictionary value collection.
public DictionaryContainsValueConstraint ContainValue(object expected)
Parameters
expected
objectThe value to be matched in the Dictionary value collection
Returns
Contains(object?)
Returns a new SomeItemsConstraint checking for the presence of a particular object in the collection.
To search for a substring instead of a collection element, use the Contains(string?) overload.
public SomeItemsConstraint Contains(object? expected)
Parameters
expected
object
Returns
Contains(string?)
Returns a new ContainsConstraint. This constraint will, in turn, make use of the appropriate second-level constraint, depending on the type of the actual argument.
To search for a collection element instead of a substring, use the Contains(object?) overload.
public ContainsConstraint Contains(string? expected)
Parameters
expected
string
Returns
EndWith(string)
Returns a constraint that succeeds if the actual value ends with the substring supplied as an argument.
public EndsWithConstraint EndWith(string expected)
Parameters
expected
string
Returns
EndsWith(string)
Returns a constraint that succeeds if the actual value ends with the substring supplied as an argument.
public EndsWithConstraint EndsWith(string expected)
Parameters
expected
string
Returns
EqualTo(object?)
Returns a constraint that tests two items for equality
public EqualConstraint EqualTo(object? expected)
Parameters
expected
object
Returns
EquivalentTo(IEnumerable)
Returns a constraint that tests whether the actual value is a collection containing the same elements as the collection supplied as an argument.
public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
Parameters
expected
IEnumerable
Returns
Exactly(int)
Returns a ConstraintExpression, which will apply the following constraint to all members of a collection, succeeding only if a specified number of them succeed.
public ItemsConstraintExpression Exactly(int expectedCount)
Parameters
expectedCount
int
Returns
GreaterThan(object)
Returns a constraint that tests whether the actual value is greater than the supplied argument
public GreaterThanConstraint GreaterThan(object expected)
Parameters
expected
object
Returns
GreaterThanOrEqualTo(object)
Returns a constraint that tests whether the actual value is greater than or equal to the supplied argument
public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
Parameters
expected
object
Returns
InRange(object, object)
Returns a constraint that tests whether the actual value falls inclusively within a specified range.
public RangeConstraint InRange(object from, object to)
Parameters
Returns
InstanceOf(Type)
Returns a constraint that tests whether the actual value is of the type supplied as an argument or a derived type.
public InstanceOfTypeConstraint InstanceOf(Type expectedType)
Parameters
expectedType
Type
Returns
InstanceOf<TExpected>()
Returns a constraint that tests whether the actual value is of the type supplied as an argument or a derived type.
public InstanceOfTypeConstraint InstanceOf<TExpected>()
Returns
Type Parameters
TExpected
ItemAt(params object[])
Returns a new IndexerConstraintExpression, which will apply any following constraint to that indexer value.
public ConstraintExpression ItemAt(params object[] indexArgs)
Parameters
indexArgs
object[]Index accessor values.
Returns
LessThan(object)
Returns a constraint that tests whether the actual value is less than the supplied argument
public LessThanConstraint LessThan(object expected)
Parameters
expected
object
Returns
LessThanOrEqualTo(object)
Returns a constraint that tests whether the actual value is less than or equal to the supplied argument
public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
Parameters
expected
object
Returns
Match(string)
Returns a constraint that succeeds if the actual value matches the regular expression supplied as an argument.
public RegexConstraint Match(string pattern)
Parameters
pattern
string
Returns
Match(Regex)
Returns a constraint that succeeds if the actual value matches the regular expression supplied as an argument.
public RegexConstraint Match(Regex regex)
Parameters
regex
Regex
Returns
Matches(IResolveConstraint)
Returns the constraint provided as an argument - used to allow custom custom constraints to easily participate in the syntax.
public Constraint Matches(IResolveConstraint constraint)
Parameters
constraint
IResolveConstraint
Returns
Matches(string)
Returns a constraint that succeeds if the actual value matches the regular expression supplied as an argument.
public RegexConstraint Matches(string pattern)
Parameters
pattern
string
Returns
Matches(Regex)
Returns a constraint that succeeds if the actual value matches the regular expression supplied as an argument.
public RegexConstraint Matches(Regex regex)
Parameters
regex
Regex
Returns
Matches<TActual>(Predicate<TActual>)
Returns the constraint provided as an argument - used to allow custom custom constraints to easily participate in the syntax.
public Constraint Matches<TActual>(Predicate<TActual> predicate)
Parameters
predicate
Predicate<TActual>
Returns
Type Parameters
TActual
Member(object?)
Returns a new SomeItemsConstraint checking for the presence of a particular object in the collection.
public SomeItemsConstraint Member(object? expected)
Parameters
expected
object
Returns
Property(string)
Returns a new PropertyConstraintExpression, which will either test for the existence of the named property on the object being tested or apply any following constraint to that property.
public ResolvableConstraintExpression Property(string name)
Parameters
name
string
Returns
SameAs(object?)
Returns a constraint that tests that two references are the same object
public SameAsConstraint SameAs(object? expected)
Parameters
expected
object
Returns
SamePath(string)
Returns a constraint that tests whether the path provided is the same as an expected path after canonicalization.
public SamePathConstraint SamePath(string expected)
Parameters
expected
string
Returns
SamePathOrUnder(string)
Returns a constraint that tests whether the path provided is the same path or under an expected path after canonicalization.
public SamePathOrUnderConstraint SamePathOrUnder(string expected)
Parameters
expected
string
Returns
StartWith(string)
Returns a constraint that succeeds if the actual value starts with the substring supplied as an argument.
public StartsWithConstraint StartWith(string expected)
Parameters
expected
string
Returns
StartsWith(string)
Returns a constraint that succeeds if the actual value starts with the substring supplied as an argument.
public StartsWithConstraint StartsWith(string expected)
Parameters
expected
string
Returns
SubPathOf(string)
Returns a constraint that tests whether the path provided is the a subpath of the expected path after canonicalization.
public SubPathConstraint SubPathOf(string expected)
Parameters
expected
string
Returns
SubsetOf(IEnumerable)
Returns a constraint that tests whether the actual value is a subset of the collection supplied as an argument.
public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
Parameters
expected
IEnumerable
Returns
SupersetOf(IEnumerable)
Returns a constraint that tests whether the actual value is a superset of the collection supplied as an argument.
public CollectionSupersetConstraint SupersetOf(IEnumerable expected)
Parameters
expected
IEnumerable
Returns
ToString()
Returns a string representation of the expression as it currently stands. This should only be used for testing, since it has the side-effect of resolving the expression.
public override string ToString()
Returns
TypeOf(Type)
Returns a constraint that tests whether the actual value is of the exact type supplied as an argument.
public ExactTypeConstraint TypeOf(Type expectedType)
Parameters
expectedType
Type
Returns
TypeOf<TExpected>()
Returns a constraint that tests whether the actual value is of the exact type supplied as an argument.
public ExactTypeConstraint TypeOf<TExpected>()
Returns
Type Parameters
TExpected