Table of Contents

Class ConstraintFactory

Namespace
NUnit.Framework.Constraints
Assembly
nunit.framework.dll

Helper class with properties and methods that supply a number of constraints used in Asserts.

public class ConstraintFactory
Inheritance
ConstraintFactory
Derived
Inherited Members

Constructors

ConstraintFactory()

public ConstraintFactory()

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

ConstraintExpression

BinarySerializable

Returns a constraint that tests whether an object graph is serializable in binary format.

public BinarySerializableConstraint BinarySerializable { get; }

Property Value

BinarySerializableConstraint

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

ResolvableConstraintExpression

Empty

Returns a constraint that tests for empty

public EmptyConstraint Empty { get; }

Property Value

EmptyConstraint

False

Returns a constraint that tests for False

public FalseConstraint False { get; }

Property Value

FalseConstraint

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

ResolvableConstraintExpression

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

ResolvableConstraintExpression

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

ResolvableConstraintExpression

NaN

Returns a constraint that tests for NaN

public NaNConstraint NaN { get; }

Property Value

NaNConstraint

Negative

Returns a constraint that tests for a negative value

public LessThanConstraint Negative { get; }

Property Value

LessThanConstraint

No

Returns a ConstraintExpression that negates any following constraint.

public ConstraintExpression No { get; }

Property Value

ConstraintExpression

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

ConstraintExpression

Not

Returns a ConstraintExpression that negates any following constraint.

public ConstraintExpression Not { get; }

Property Value

ConstraintExpression

Null

Returns a constraint that tests for null

public NullConstraint Null { get; }

Property Value

NullConstraint

Ordered

Returns a constraint that tests whether a collection is ordered

public CollectionOrderedConstraint Ordered { get; }

Property Value

CollectionOrderedConstraint

Positive

Returns a constraint that tests for a positive value

public GreaterThanConstraint Positive { get; }

Property Value

GreaterThanConstraint

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

ConstraintExpression

True

Returns a constraint that tests for True

public TrueConstraint True { get; }

Property Value

TrueConstraint

Unique

Returns a constraint that tests whether a collection contains all unique items.

public UniqueItemsConstraint Unique { get; }

Property Value

UniqueItemsConstraint

XmlSerializable

Returns a constraint that tests whether an object graph is serializable in xml format.

public XmlSerializableConstraint XmlSerializable { get; }

Property Value

XmlSerializableConstraint

Methods

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

AssignableFromConstraint

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

AssignableFromConstraint

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

AssignableToConstraint

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

AssignableToConstraint

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

GreaterThanOrEqualConstraint

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

LessThanOrEqualConstraint

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

ResolvableConstraintExpression

Attribute<TExpected>()

Returns a new AttributeConstraint checking for the presence of a particular attribute on an object.

public ResolvableConstraintExpression Attribute<TExpected>()

Returns

ResolvableConstraintExpression

Type Parameters

TExpected

Contains(object)

Returns a new CollectionContainsConstraint checking for the presence of a particular object in the collection.

public CollectionContainsConstraint Contains(object expected)

Parameters

expected object

Returns

CollectionContainsConstraint

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. 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 Contains(string expected)

Parameters

expected string

Returns

ContainsConstraint

ContainsSubstring(string)

Returns a constraint that succeeds if the actual value contains the substring supplied as an argument.

[Obsolete("Deprecated, use Contains")]
public SubstringConstraint ContainsSubstring(string expected)

Parameters

expected string

Returns

SubstringConstraint

DoesNotContain(string)

Returns a constraint that fails if the actual value contains the substring supplied as an argument.

[Obsolete("Deprecated, use Does.Not.Contain")]
public SubstringConstraint DoesNotContain(string expected)

Parameters

expected string

Returns

SubstringConstraint

DoesNotEndWith(string)

Returns a constraint that fails if the actual value ends with the substring supplied as an argument.

[Obsolete("Deprecated, use Does.Not.EndWith")]
public EndsWithConstraint DoesNotEndWith(string expected)

Parameters

expected string

Returns

EndsWithConstraint

DoesNotMatch(string)

Returns a constraint that fails if the actual value matches the pattern supplied as an argument.

[Obsolete("Deprecated, use Does.Not.Match")]
public RegexConstraint DoesNotMatch(string pattern)

Parameters

pattern string

Returns

RegexConstraint

DoesNotStartWith(string)

Returns a constraint that fails if the actual value starts with the substring supplied as an argument.

[Obsolete("Deprecated, use Does.Not.StartWith")]
public StartsWithConstraint DoesNotStartWith(string expected)

Parameters

expected string

Returns

StartsWithConstraint

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

EndsWithConstraint

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

EndsWithConstraint

EqualTo(object)

Returns a constraint that tests two items for equality

public EqualConstraint EqualTo(object expected)

Parameters

expected object

Returns

EqualConstraint

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

CollectionEquivalentConstraint

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 static ConstraintExpression Exactly(int expectedCount)

Parameters

expectedCount int

Returns

ConstraintExpression

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

GreaterThanConstraint

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

GreaterThanOrEqualConstraint

InRange(IComparable, IComparable)

Returns a constraint that tests whether the actual value falls within a specified range.

public RangeConstraint InRange(IComparable from, IComparable to)

Parameters

from IComparable
to IComparable

Returns

RangeConstraint

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

InstanceOfTypeConstraint

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

InstanceOfTypeConstraint

Type Parameters

TExpected

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

LessThanConstraint

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

LessThanOrEqualConstraint

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

RegexConstraint

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

RegexConstraint

Member(object)

Returns a new CollectionContainsConstraint checking for the presence of a particular object in the collection.

public CollectionContainsConstraint Member(object expected)

Parameters

expected object

Returns

CollectionContainsConstraint

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

ResolvableConstraintExpression

SameAs(object)

Returns a constraint that tests that two references are the same object

public SameAsConstraint SameAs(object expected)

Parameters

expected object

Returns

SameAsConstraint

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

SamePathConstraint

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

SamePathOrUnderConstraint

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

StartsWithConstraint

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

StartsWithConstraint

StringContaining(string)

Returns a constraint that succeeds if the actual value contains the substring supplied as an argument.

[Obsolete("Deprecated, use Contains")]
public SubstringConstraint StringContaining(string expected)

Parameters

expected string

Returns

SubstringConstraint

StringEnding(string)

Returns a constraint that succeeds if the actual value ends with the substring supplied as an argument.

[Obsolete("Deprecated, use Does.EndWith or EndsWith")]
public EndsWithConstraint StringEnding(string expected)

Parameters

expected string

Returns

EndsWithConstraint

StringMatching(string)

Returns a constraint that succeeds if the actual value matches the regular expression supplied as an argument.

[Obsolete("Deprecated, use Does.Match or Matches")]
public RegexConstraint StringMatching(string pattern)

Parameters

pattern string

Returns

RegexConstraint

StringStarting(string)

Returns a constraint that succeeds if the actual value starts with the substring supplied as an argument.

[Obsolete("Deprecated, use Does.StartWith or StartsWith")]
public StartsWithConstraint StringStarting(string expected)

Parameters

expected string

Returns

StartsWithConstraint

SubPathOf(string)

Returns a constraint that tests whether the path provided is a subpath of the expected path after canonicalization.

public SubPathConstraint SubPathOf(string expected)

Parameters

expected string

Returns

SubPathConstraint

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

CollectionSubsetConstraint

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

CollectionSupersetConstraint

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

ExactTypeConstraint

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

ExactTypeConstraint

Type Parameters

TExpected