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.
Inheritance
ConstraintExpression
Assembly: nunit.framework.dll
Syntax
public class ConstraintExpression
Constructors
View Source
ConstraintExpression()
Declaration
public ConstraintExpression()
View Source
ConstraintExpression(ConstraintBuilder)
Initializes a new instance of the ConstraintExpression
class passing in a ConstraintBuilder, which may be pre-populated.
Declaration
public ConstraintExpression(ConstraintBuilder builder)
Parameters
Fields
View Source
builder
The ConstraintBuilder holding the elements recognized so far
Declaration
protected readonly ConstraintBuilder builder
Field Value
Properties
View Source
All
Returns a ConstraintExpression, which will apply
the following constraint to all members of a collection,
succeeding if all of them succeed.
Declaration
public ConstraintExpression All { get; }
Property Value
View Source
Count
Returns a new ConstraintExpression, which will apply the following
constraint to the Count property of the object being tested.
Declaration
public ResolvableConstraintExpression Count { get; }
Property Value
View Source
Default
Returns a constraint that tests for default value
Declaration
public DefaultConstraint Default { get; }
Property Value
View Source
Empty
Returns a constraint that tests for empty
Declaration
public EmptyConstraint Empty { get; }
Property Value
View Source
Exist
Returns a constraint that succeeds if the value
is a file or directory and it exists.
Declaration
public Constraint Exist { get; }
Property Value
View Source
False
Returns a constraint that tests for False
Declaration
public FalseConstraint False { get; }
Property Value
View Source
InnerException
Returns a new ConstraintExpression, which will apply the following
constraint to the InnerException property of the object being tested.
Declaration
public ResolvableConstraintExpression InnerException { get; }
Property Value
View Source
Length
Returns a new ConstraintExpression, which will apply the following
constraint to the Length property of the object being tested.
Declaration
public ResolvableConstraintExpression Length { get; }
Property Value
View Source
Message
Returns a new ConstraintExpression, which will apply the following
constraint to the Message property of the object being tested.
Declaration
public ResolvableConstraintExpression Message { get; }
Property Value
View Source
NaN
Returns a constraint that tests for NaN
Declaration
public NaNConstraint NaN { get; }
Property Value
View Source
Negative
Returns a constraint that tests for a negative value
Declaration
public LessThanConstraint Negative { get; }
Property Value
View Source
No
Returns a ConstraintExpression that negates any
following constraint.
Declaration
public ConstraintExpression No { get; }
Property Value
View Source
None
Returns a ConstraintExpression, which will apply
the following constraint to all members of a collection,
succeeding if all of them fail.
Declaration
public ConstraintExpression None { get; }
Property Value
View Source
Not
Returns a ConstraintExpression that negates any
following constraint.
Declaration
public ConstraintExpression Not { get; }
Property Value
View Source
Null
Returns a constraint that tests for null
Declaration
public NullConstraint Null { get; }
Property Value
View Source
One
Returns a ItemsConstraintExpression, which will
apply the following constraint to a collection of length one, succeeding
only if exactly one of them succeeds.
Declaration
public ItemsConstraintExpression One { get; }
Property Value
View Source
Ordered
Returns a constraint that tests whether a collection is ordered
Declaration
public CollectionOrderedConstraint Ordered { get; }
Property Value
View Source
Positive
Returns a constraint that tests for a positive value
Declaration
public GreaterThanConstraint Positive { get; }
Property Value
View Source
Some
Returns a ConstraintExpression, which will apply
the following constraint to all members of a collection,
succeeding if at least one of them succeeds.
Declaration
public ConstraintExpression Some { get; }
Property Value
View Source
True
Returns a constraint that tests for True
Declaration
public TrueConstraint True { get; }
Property Value
View Source
Unique
Returns a constraint that tests whether a collection
contains all unique items.
Declaration
public UniqueItemsConstraint Unique { get; }
Property Value
View Source
WhiteSpace
Returns a constraint that tests for white-space
Declaration
public WhiteSpaceConstraint WhiteSpace { get; }
Property Value
View Source
With
With is currently a NOP - reserved for future use.
Declaration
public ConstraintExpression With { get; }
Property Value
View Source
XmlSerializable
Returns a constraint that tests whether an object graph is serializable in XML format.
Declaration
public XmlSerializableConstraint XmlSerializable { get; }
Property Value
View Source
Zero
Returns a constraint that tests if item is equal to zero
Declaration
public EqualConstraint Zero { get; }
Property Value
Methods
View Source
AnyOf(ICollection)
Returns a constraint that tests if an item is equal to any of expected values
Declaration
public AnyOfConstraint AnyOf(ICollection expected)
Parameters
Type |
Name |
Description |
ICollection |
expected |
Expected values
|
Returns
View Source
AnyOf(params object?[]?)
Returns a constraint that tests if an item is equal to any of parameters
Declaration
public AnyOfConstraint AnyOf(params object?[]? expected)
Parameters
Type |
Name |
Description |
object[] |
expected |
Expected values
|
Returns
View Source
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.
Declaration
public Constraint Append(Constraint constraint)
Parameters
Returns
View Source
Append(ConstraintOperator)
Appends an operator to the expression and returns the
resulting expression itself.
Declaration
public ConstraintExpression Append(ConstraintOperator op)
Parameters
Returns
View Source
Append(SelfResolvingOperator)
Appends a self-resolving operator to the expression and
returns a new ResolvableConstraintExpression.
Declaration
public ResolvableConstraintExpression Append(SelfResolvingOperator op)
Parameters
Returns
View Source
Append<T>(T)
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.
Declaration
public T Append<T>(T constraint) where T : Constraint
Parameters
Type |
Name |
Description |
T |
constraint |
|
Returns
Type Parameters
View Source
AssignableFrom(Type)
Returns a constraint that tests whether the actual value
is assignable from the type supplied as an argument.
Declaration
public AssignableFromConstraint AssignableFrom(Type expectedType)
Parameters
Type |
Name |
Description |
Type |
expectedType |
|
Returns
View Source
AssignableFrom<TExpected>()
Returns a constraint that tests whether the actual value
is assignable from the type supplied as an argument.
Declaration
public AssignableFromConstraint AssignableFrom<TExpected>()
Returns
Type Parameters
Name |
Description |
TExpected |
|
View Source
AssignableTo(Type)
Returns a constraint that tests whether the actual value
is assignable from the type supplied as an argument.
Declaration
public AssignableToConstraint AssignableTo(Type expectedType)
Parameters
Type |
Name |
Description |
Type |
expectedType |
|
Returns
View Source
AssignableTo<TExpected>()
Returns a constraint that tests whether the actual value
is assignable from the type supplied as an argument.
Declaration
public AssignableToConstraint AssignableTo<TExpected>()
Returns
Type Parameters
Name |
Description |
TExpected |
|
View Source
AtLeast(object)
Returns a constraint that tests whether the
actual value is greater than or equal to the supplied argument
Declaration
public GreaterThanOrEqualConstraint AtLeast(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
AtMost(object)
Returns a constraint that tests whether the
actual value is less than or equal to the supplied argument
Declaration
public LessThanOrEqualConstraint AtMost(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
Attribute(Type)
Returns a new AttributeConstraint checking for the
presence of a particular attribute on an object.
Declaration
public ResolvableConstraintExpression Attribute(Type expectedType)
Parameters
Type |
Name |
Description |
Type |
expectedType |
|
Returns
View Source
Attribute<TExpected>()
Returns a new AttributeConstraint checking for the
presence of a particular attribute on an object.
Declaration
public ResolvableConstraintExpression Attribute<TExpected>()
Returns
Type Parameters
Name |
Description |
TExpected |
|
View Source
Contain(object?)
Returns a new SomeItemsConstraint checking for the
presence of a particular object in the collection.
Declaration
public SomeItemsConstraint Contain(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
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.
Declaration
public ContainsConstraint Contain(string? expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
ContainKey(object)
Returns a new DictionaryContainsKeyConstraint checking for the
presence of a particular key in the Dictionary key collection.
Declaration
public DictionaryContainsKeyConstraint ContainKey(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
The key to be matched in the Dictionary key collection
|
Returns
View Source
ContainValue(object?)
Returns a new DictionaryContainsValueConstraint checking for the
presence of a particular value in the Dictionary value collection.
Declaration
public DictionaryContainsValueConstraint ContainValue(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
The value to be matched in the Dictionary value collection
|
Returns
View Source
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.
Declaration
public SomeItemsConstraint Contains(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
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.
Declaration
public ContainsConstraint Contains(string? expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
EndWith(string)
Returns a constraint that succeeds if the actual
value ends with the substring supplied as an argument.
Declaration
public EndsWithConstraint EndWith(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
EndsWith(string)
Returns a constraint that succeeds if the actual
value ends with the substring supplied as an argument.
Declaration
public EndsWithConstraint EndsWith(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
EqualTo(object?)
Returns a constraint that tests two items for equality
Declaration
public EqualConstraint EqualTo(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
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.
Declaration
public CollectionEquivalentConstraint EquivalentTo(IEnumerable expected)
Parameters
Returns
View Source
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.
Declaration
public ItemsConstraintExpression Exactly(int expectedCount)
Parameters
Type |
Name |
Description |
int |
expectedCount |
|
Returns
View Source
GreaterThan(object)
Returns a constraint that tests whether the
actual value is greater than the supplied argument
Declaration
public GreaterThanConstraint GreaterThan(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
GreaterThanOrEqualTo(object)
Returns a constraint that tests whether the
actual value is greater than or equal to the supplied argument
Declaration
public GreaterThanOrEqualConstraint GreaterThanOrEqualTo(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
InRange(object, object)
Returns a constraint that tests whether the actual value falls
inclusively within a specified range.
Declaration
public RangeConstraint InRange(object from, object to)
Parameters
Type |
Name |
Description |
object |
from |
Inclusive beginning of the range.
|
object |
to |
Inclusive end of the range.
|
Returns
View Source
InstanceOf(Type)
Returns a constraint that tests whether the actual value
is of the type supplied as an argument or a derived type.
Declaration
public InstanceOfTypeConstraint InstanceOf(Type expectedType)
Parameters
Type |
Name |
Description |
Type |
expectedType |
|
Returns
View Source
InstanceOf<TExpected>()
Returns a constraint that tests whether the actual value
is of the type supplied as an argument or a derived type.
Declaration
public InstanceOfTypeConstraint InstanceOf<TExpected>()
Returns
Type Parameters
Name |
Description |
TExpected |
|
View Source
ItemAt(params object[])
Returns a new IndexerConstraintExpression, which will
apply any following constraint to that indexer value.
Declaration
public ConstraintExpression ItemAt(params object[] indexArgs)
Parameters
Type |
Name |
Description |
object[] |
indexArgs |
Index accessor values.
|
Returns
View Source
LessThan(object)
Returns a constraint that tests whether the
actual value is less than the supplied argument
Declaration
public LessThanConstraint LessThan(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
LessThanOrEqualTo(object)
Returns a constraint that tests whether the
actual value is less than or equal to the supplied argument
Declaration
public LessThanOrEqualConstraint LessThanOrEqualTo(object expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
Match(string)
Returns a constraint that succeeds if the actual
value matches the regular expression supplied as an argument.
Declaration
public RegexConstraint Match(string pattern)
Parameters
Type |
Name |
Description |
string |
pattern |
|
Returns
View Source
Match(Regex)
Returns a constraint that succeeds if the actual
value matches the regular expression supplied as an argument.
Declaration
public RegexConstraint Match(Regex regex)
Parameters
Type |
Name |
Description |
Regex |
regex |
|
Returns
View Source
Matches(IResolveConstraint)
Returns the constraint provided as an argument - used to allow custom
custom constraints to easily participate in the syntax.
Declaration
public Constraint Matches(IResolveConstraint constraint)
Parameters
Returns
View Source
Matches(string)
Returns a constraint that succeeds if the actual
value matches the regular expression supplied as an argument.
Declaration
public RegexConstraint Matches(string pattern)
Parameters
Type |
Name |
Description |
string |
pattern |
|
Returns
View Source
Matches(Regex)
Returns a constraint that succeeds if the actual
value matches the regular expression supplied as an argument.
Declaration
public RegexConstraint Matches(Regex regex)
Parameters
Type |
Name |
Description |
Regex |
regex |
|
Returns
View Source
Matches<TActual>(Predicate<TActual>)
Returns the constraint provided as an argument - used to allow custom
custom constraints to easily participate in the syntax.
Declaration
public Constraint Matches<TActual>(Predicate<TActual> predicate)
Parameters
Type |
Name |
Description |
Predicate<TActual> |
predicate |
|
Returns
Type Parameters
View Source
Member(object?)
Returns a new SomeItemsConstraint checking for the
presence of a particular object in the collection.
Declaration
public SomeItemsConstraint Member(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
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.
Declaration
public ResolvableConstraintExpression Property(string name)
Parameters
Type |
Name |
Description |
string |
name |
|
Returns
View Source
SameAs(object?)
Returns a constraint that tests that two references are the same object
Declaration
public SameAsConstraint SameAs(object? expected)
Parameters
Type |
Name |
Description |
object |
expected |
|
Returns
View Source
SamePath(string)
Returns a constraint that tests whether the path provided
is the same as an expected path after canonicalization.
Declaration
public SamePathConstraint SamePath(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
SamePathOrUnder(string)
Returns a constraint that tests whether the path provided
is the same path or under an expected path after canonicalization.
Declaration
public SamePathOrUnderConstraint SamePathOrUnder(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
StartWith(string)
Returns a constraint that succeeds if the actual
value starts with the substring supplied as an argument.
Declaration
public StartsWithConstraint StartWith(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
StartsWith(string)
Returns a constraint that succeeds if the actual
value starts with the substring supplied as an argument.
Declaration
public StartsWithConstraint StartsWith(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
SubPathOf(string)
Returns a constraint that tests whether the path provided
is the a subpath of the expected path after canonicalization.
Declaration
public SubPathConstraint SubPathOf(string expected)
Parameters
Type |
Name |
Description |
string |
expected |
|
Returns
View Source
SubsetOf(IEnumerable)
Returns a constraint that tests whether the actual value
is a subset of the collection supplied as an argument.
Declaration
public CollectionSubsetConstraint SubsetOf(IEnumerable expected)
Parameters
Returns
View Source
SupersetOf(IEnumerable)
Returns a constraint that tests whether the actual value
is a superset of the collection supplied as an argument.
Declaration
public CollectionSupersetConstraint SupersetOf(IEnumerable expected)
Parameters
Returns
View Source
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.
Declaration
public override string ToString()
Returns
Overrides
View Source
TypeOf(Type)
Returns a constraint that tests whether the actual
value is of the exact type supplied as an argument.
Declaration
public ExactTypeConstraint TypeOf(Type expectedType)
Parameters
Type |
Name |
Description |
Type |
expectedType |
|
Returns
View Source
TypeOf<TExpected>()
Returns a constraint that tests whether the actual
value is of the exact type supplied as an argument.
Declaration
public ExactTypeConstraint TypeOf<TExpected>()
Returns
Type Parameters
Name |
Description |
TExpected |
|