Search Results for

    Show / Hide Table of Contents

    Class Constraint

    The Constraint class is the base of all built-in constraints within NUnit. It provides the operator overloads used to combine constraints.

    Inheritance
    object
    Constraint
    AnyOfConstraint
    AttributeExistsConstraint
    BinaryConstraint
    CollectionConstraint
    ComparisonConstraint
    ContainsConstraint
    CountZeroConstraint
    DefaultConstraint
    EmptyConstraint
    EmptyDirectoryConstraint
    EmptyGuidConstraint
    EqualConstraint
    EqualDateTimeOffsetConstraintWithSameOffset
    EqualNumericWithoutUsingConstraint<T>
    EqualStringWithoutUsingConstraint
    EqualTimeBaseConstraint<T>
    EqualTimeBasedConstraintWithTimeSpanTolerance<T>
    EqualUsingConstraint<T>
    ExactCountConstraint
    FalseConstraint
    FileOrDirectoryExistsConstraint
    NaNConstraint
    NullConstraint
    PredicateConstraint<T>
    PrefixConstraint
    PropertyExistsConstraint
    RangeConstraint
    RegexConstraint
    SameAsConstraint
    StringConstraint
    ThrowsExceptionConstraint
    ThrowsNothingConstraint
    TrueConstraint
    TypeConstraint
    XmlSerializableConstraint
    Implements
    IConstraint
    IResolveConstraint
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: NUnit.Framework.Constraints
    Assembly: nunit.framework.dll
    Syntax
    public abstract class Constraint : IConstraint, IResolveConstraint

    Constructors

    View Source

    Constraint(params object?[])

    Construct a constraint with optional arguments

    Declaration
    protected Constraint(params object?[] args)
    Parameters
    Type Name Description
    object[] args

    Arguments to be saved

    Properties

    View Source

    And

    Returns a ConstraintExpression by appending And to the current constraint.

    Declaration
    public ConstraintExpression And { get; }
    Property Value
    Type Description
    ConstraintExpression
    View Source

    Arguments

    Arguments provided to this Constraint, for use in formatting the description.

    Declaration
    public object?[] Arguments { get; }
    Property Value
    Type Description
    object[]
    View Source

    Builder

    The ConstraintBuilder holding this constraint

    Declaration
    public ConstraintBuilder? Builder { get; set; }
    Property Value
    Type Description
    ConstraintBuilder
    View Source

    Description

    The Description of what this constraint tests, for use in messages and in the ConstraintResult.

    Declaration
    public abstract string Description { get; }
    Property Value
    Type Description
    string
    View Source

    DisplayName

    The display name of this Constraint for use by ToString(). The default value is the name of the constraint with trailing "Constraint" removed. Derived classes may set this to another name in their constructors.

    Declaration
    public virtual string DisplayName { get; }
    Property Value
    Type Description
    string
    View Source

    Or

    Returns a ConstraintExpression by appending Or to the current constraint.

    Declaration
    public ConstraintExpression Or { get; }
    Property Value
    Type Description
    ConstraintExpression
    View Source

    With

    Returns a ConstraintExpression by appending And to the current constraint.

    Declaration
    public ConstraintExpression With { get; }
    Property Value
    Type Description
    ConstraintExpression

    Methods

    View Source

    After(int)

    Returns a DelayedConstraint.WithRawDelayInterval with the specified delay time.

    Declaration
    public DelayedConstraint.WithRawDelayInterval After(int delay)
    Parameters
    Type Name Description
    int delay

    The delay, which defaults to milliseconds.

    Returns
    Type Description
    DelayedConstraint.WithRawDelayInterval
    View Source

    After(int, int)

    Returns a DelayedConstraint with the specified delay time and polling interval.

    Declaration
    public DelayedConstraint After(int delayInMilliseconds, int pollingInterval)
    Parameters
    Type Name Description
    int delayInMilliseconds

    The delay in milliseconds.

    int pollingInterval

    The interval at which to test the constraint, in milliseconds.

    Returns
    Type Description
    DelayedConstraint
    View Source

    ApplyToAsync<TActual>(Func<Task<TActual>>)

    Applies the constraint to a delegate that returns the task. The default implementation simply evaluates the delegate and awaits the task but derived classes may override it to provide for delayed processing.

    Declaration
    public virtual Task<ConstraintResult> ApplyToAsync<TActual>(Func<Task<TActual>> taskDel)
    Parameters
    Type Name Description
    Func<Task<TActual>> taskDel
    Returns
    Type Description
    Task<ConstraintResult>
    Type Parameters
    Name Description
    TActual
    View Source

    ApplyTo<TActual>(ActualValueDelegate<TActual>)

    Applies the constraint to an ActualValueDelegate that returns the value to be tested. The default implementation simply evaluates the delegate but derived classes may override it to provide for delayed processing.

    Declaration
    public virtual ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del

    An ActualValueDelegate

    Returns
    Type Description
    ConstraintResult

    A ConstraintResult

    Type Parameters
    Name Description
    TActual
    View Source

    ApplyTo<TActual>(TActual)

    Applies the constraint to an actual value, returning a ConstraintResult.

    Declaration
    public abstract ConstraintResult ApplyTo<TActual>(TActual actual)
    Parameters
    Type Name Description
    TActual actual

    The value to be tested

    Returns
    Type Description
    ConstraintResult

    A ConstraintResult

    Type Parameters
    Name Description
    TActual
    View Source

    ApplyTo<TActual>(ref TActual)

    Test whether the constraint is satisfied by a given reference. The default implementation simply dereferences the value but derived classes may override it to provide for delayed processing.

    Declaration
    public virtual ConstraintResult ApplyTo<TActual>(ref TActual actual)
    Parameters
    Type Name Description
    TActual actual

    A reference to the value to be tested

    Returns
    Type Description
    ConstraintResult

    A ConstraintResult

    Type Parameters
    Name Description
    TActual
    View Source

    GetStringRepresentation()

    Returns the string representation of this constraint

    Declaration
    protected virtual string GetStringRepresentation()
    Returns
    Type Description
    string
    View Source

    GetStringRepresentation(IEnumerable)

    Returns the string representation of this constraint and the passed in arguments

    Declaration
    protected string GetStringRepresentation(IEnumerable arguments)
    Parameters
    Type Name Description
    IEnumerable arguments
    Returns
    Type Description
    string
    View Source

    GetTestObject<TActual>(ActualValueDelegate<TActual>)

    Retrieves the value to be tested from an ActualValueDelegate. The default implementation simply evaluates the delegate but derived classes may override it to provide for delayed processing.

    Declaration
    protected virtual object? GetTestObject<TActual>(ActualValueDelegate<TActual> del)
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del

    An ActualValueDelegate

    Returns
    Type Description
    object

    Delegate evaluation result

    Type Parameters
    Name Description
    TActual
    View Source

    ToString()

    Default override of ToString returns the constraint DisplayName followed by any arguments within angle brackets.

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    object.ToString()

    Operators

    View Source

    operator &(Constraint, Constraint)

    This operator creates a constraint that is satisfied only if both argument constraints are satisfied.

    Declaration
    public static Constraint operator &(Constraint left, Constraint right)
    Parameters
    Type Name Description
    Constraint left
    Constraint right
    Returns
    Type Description
    Constraint
    View Source

    operator |(Constraint, Constraint)

    This operator creates a constraint that is satisfied if either of the argument constraints is satisfied.

    Declaration
    public static Constraint operator |(Constraint left, Constraint right)
    Parameters
    Type Name Description
    Constraint left
    Constraint right
    Returns
    Type Description
    Constraint
    View Source

    operator !(Constraint)

    This operator creates a constraint that is satisfied if the argument constraint is not satisfied.

    Declaration
    public static Constraint operator !(Constraint constraint)
    Parameters
    Type Name Description
    Constraint constraint
    Returns
    Type Description
    Constraint

    Implements

    IConstraint
    IResolveConstraint
    • View Source
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0