Search Results for

    Show / Hide Table of Contents

    Class EqualConstraint

    EqualConstraint is able to compare an actual value with the expected value provided in its constructor. Two objects are considered equal if both are null, or if both have the same value. NUnit has special semantics for some object types.

    Inheritance
    object
    Constraint
    EqualConstraint
    Implements
    IConstraint
    IResolveConstraint
    Inherited Members
    Constraint.ApplyTo<TActual>(ActualValueDelegate<TActual>)
    Constraint.ApplyTo<TActual>(ref TActual)
    Constraint.ApplyToAsync<TActual>(Func<Task<TActual>>)
    Constraint.GetTestObject<TActual>(ActualValueDelegate<TActual>)
    Constraint.ToString()
    Constraint.GetStringRepresentation(IEnumerable)
    Constraint.GetStringRepresentation()
    Constraint.After(int)
    Constraint.After(int, int)
    Constraint.DisplayName
    Constraint.Arguments
    Constraint.Builder
    Constraint.And
    Constraint.With
    Constraint.Or
    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 class EqualConstraint : Constraint, IConstraint, IResolveConstraint

    Constructors

    View Source

    EqualConstraint(object?)

    Initializes a new instance of the EqualConstraint class.

    Declaration
    public EqualConstraint(object? expected)
    Parameters
    Type Name Description
    object expected

    The expected value.

    Properties

    View Source

    AsCollection

    Flag the constraint to compare arrays as collections and return self.

    Declaration
    public EqualConstraint AsCollection { get; }
    Property Value
    Type Description
    EqualConstraint
    View Source

    CaseInsensitive

    Gets a value indicating whether to compare case insensitive.

    Declaration
    public bool CaseInsensitive { get; }
    Property Value
    Type Description
    bool

    true if comparing case insensitive; otherwise, false.

    View Source

    ClipStrings

    Gets a value indicating whether or not to clip strings.

    Declaration
    public bool ClipStrings { get; }
    Property Value
    Type Description
    bool

    true if set to clip strings otherwise, false.

    View Source

    ComparingProperties

    Gets a value indicating whether to compare separate properties.

    Declaration
    public bool ComparingProperties { get; }
    Property Value
    Type Description
    bool

    true if comparing separate properties; otherwise, false.

    View Source

    Days

    Causes the tolerance to be interpreted as a TimeSpan in days.

    Declaration
    public EqualConstraint Days { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    Description

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

    Declaration
    public override string Description { get; }
    Property Value
    Type Description
    string
    Overrides
    Constraint.Description
    View Source

    FailurePoints

    Gets the failure points.

    Declaration
    public IList<NUnitEqualityComparer.FailurePoint> FailurePoints { get; }
    Property Value
    Type Description
    IList<NUnitEqualityComparer.FailurePoint>

    The failure points.

    View Source

    HasFailurePoints

    Gets a value indicating whether there is any additional Failure Information.

    Declaration
    public bool HasFailurePoints { get; }
    Property Value
    Type Description
    bool
    View Source

    Hours

    Causes the tolerance to be interpreted as a TimeSpan in hours.

    Declaration
    public EqualConstraint Hours { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    IgnoreCase

    Flag the constraint to ignore case and return self.

    Declaration
    public EqualConstraint IgnoreCase { get; }
    Property Value
    Type Description
    EqualConstraint
    View Source

    IgnoreWhiteSpace

    Flag the constraint to ignore white space and return self.

    Declaration
    public EqualConstraint IgnoreWhiteSpace { get; }
    Property Value
    Type Description
    EqualConstraint
    View Source

    IgnoringWhiteSpace

    Gets a value indicating whether to compare ignoring white space.

    Declaration
    public bool IgnoringWhiteSpace { get; }
    Property Value
    Type Description
    bool

    true if comparing ignoreing white space; otherwise, false.

    View Source

    Milliseconds

    Causes the tolerance to be interpreted as a TimeSpan in milliseconds.

    Declaration
    public EqualConstraint Milliseconds { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    Minutes

    Causes the tolerance to be interpreted as a TimeSpan in minutes.

    Declaration
    public EqualConstraint Minutes { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    NoClip

    Flag the constraint to suppress string clipping and return self.

    Declaration
    public EqualConstraint NoClip { get; }
    Property Value
    Type Description
    EqualConstraint
    View Source

    Percent

    Switches the .Within() modifier to interpret its tolerance as a percentage that the actual values is allowed to deviate from the expected value.

    Declaration
    public EqualConstraint Percent { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    Seconds

    Causes the tolerance to be interpreted as a TimeSpan in seconds.

    Declaration
    public EqualConstraint Seconds { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    Ticks

    Causes the tolerance to be interpreted as a TimeSpan in clock ticks.

    Declaration
    public EqualConstraint Ticks { get; }
    Property Value
    Type Description
    EqualConstraint

    Self

    View Source

    Tolerance

    Gets the tolerance for this comparison.

    Declaration
    public Tolerance Tolerance { get; }
    Property Value
    Type Description
    Tolerance

    The tolerance.

    View Source

    Ulps

    Switches the .Within() modifier to interpret its tolerance as a distance in representable values (see remarks).

    Declaration
    public EqualConstraint Ulps { get; }
    Property Value
    Type Description
    EqualConstraint

    Self.

    Remarks

    Ulp stands for "unit in the last place" and describes the minimum amount a given value can change. For any integers, an ulp is 1 whole digit. For floating point values, the accuracy of which is better for smaller numbers and worse for larger numbers, an ulp depends on the size of the number. Using ulps for comparison of floating point results instead of fixed tolerances is safer because it will automatically compensate for the added inaccuracy of larger numbers.

    View Source

    WithSameOffset

    Flags the constraint to include Offset property in comparison of two DateTimeOffset values.

    Declaration
    public EqualConstraint WithSameOffset { get; }
    Property Value
    Type Description
    EqualConstraint
    Remarks

    Using this modifier does not allow to use the Within(object) constraint modifier.

    Methods

    View Source

    ApplyTo<TActual>(TActual)

    Test whether the constraint is satisfied by a given value

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

    The value to be tested

    Returns
    Type Description
    ConstraintResult

    True for success, false for failure

    Type Parameters
    Name Description
    TActual
    Overrides
    Constraint.ApplyTo<TActual>(TActual)
    View Source

    Using(IComparer)

    Flag the constraint to use the supplied IComparer object.

    Declaration
    public EqualConstraint Using(IComparer comparer)
    Parameters
    Type Name Description
    IComparer comparer

    The IComparer object to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    View Source

    Using(IEqualityComparer)

    Flag the constraint to use the supplied IEqualityComparer object.

    Declaration
    public EqualConstraint Using(IEqualityComparer comparer)
    Parameters
    Type Name Description
    IEqualityComparer comparer

    The IComparer object to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    View Source

    UsingPropertiesComparer()

    Enables comparing of instance properties.

    Declaration
    public EqualConstraint UsingPropertiesComparer()
    Returns
    Type Description
    EqualConstraint
    Remarks

    This allows comparing classes that don't implement IEquatable<T> without having to compare each property separately in own code.

    View Source

    Using<T>(IComparer<T>)

    Flag the constraint to use the supplied IComparer object.

    Declaration
    public EqualConstraint Using<T>(IComparer<T> comparer)
    Parameters
    Type Name Description
    IComparer<T> comparer

    The IComparer object to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    Type Parameters
    Name Description
    T
    View Source

    Using<T>(IEqualityComparer<T>)

    Flag the constraint to use the supplied IEqualityComparer object.

    Declaration
    public EqualConstraint Using<T>(IEqualityComparer<T> comparer)
    Parameters
    Type Name Description
    IEqualityComparer<T> comparer

    The IComparer object to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    Type Parameters
    Name Description
    T
    View Source

    Using<T>(Comparison<T>)

    Flag the constraint to use the supplied Comparison object.

    Declaration
    public EqualConstraint Using<T>(Comparison<T> comparer)
    Parameters
    Type Name Description
    Comparison<T> comparer

    The IComparer object to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    Type Parameters
    Name Description
    T
    View Source

    Using<T>(Func<T, T, bool>)

    Flag the constraint to use the supplied boolean-returning delegate.

    Declaration
    public EqualConstraint Using<T>(Func<T, T, bool> comparer)
    Parameters
    Type Name Description
    Func<T, T, bool> comparer

    The boolean-returning delegate to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    Type Parameters
    Name Description
    T
    View Source

    Using<TActual, TExpected>(Func<TActual, TExpected, bool>)

    Flag the constraint to use the supplied predicate function

    Declaration
    public EqualConstraint Using<TActual, TExpected>(Func<TActual, TExpected, bool> comparison)
    Parameters
    Type Name Description
    Func<TActual, TExpected, bool> comparison

    The comparison function to use.

    Returns
    Type Description
    EqualConstraint

    Self.

    Type Parameters
    Name Description
    TActual

    The type of the actual value. Note for collection comparisons this is the element type.

    TExpected

    The type of the expected value. Note for collection comparisons this is the element type.

    View Source

    Within(object)

    Flag the constraint to use a tolerance when determining equality.

    Declaration
    public EqualConstraint Within(object amount)
    Parameters
    Type Name Description
    object amount

    Tolerance value to be used

    Returns
    Type Description
    EqualConstraint

    Self.

    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