Search Results for

    Show / Hide Table of Contents

    Class ThrowsConstraint

    ThrowsConstraint is used to test the exception thrown by a delegate by applying a constraint to it.

    Inheritance
    object
    Constraint
    PrefixConstraint
    ThrowsConstraint
    Implements
    IConstraint
    IResolveConstraint
    Inherited Members
    PrefixConstraint.BaseConstraint
    PrefixConstraint.DescriptionPrefix
    Constraint.ApplyTo<TActual>(ref 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 ThrowsConstraint : PrefixConstraint, IConstraint, IResolveConstraint

    Constructors

    View Source

    ThrowsConstraint(IConstraint)

    Initializes a new instance of the ThrowsConstraint class, using a constraint to be applied to the exception.

    Declaration
    public ThrowsConstraint(IConstraint baseConstraint)
    Parameters
    Type Name Description
    IConstraint baseConstraint

    A constraint to apply to the caught exception.

    Properties

    View Source

    ActualException

    Get the actual exception thrown - used by Assert.Throws.

    Declaration
    public Exception? ActualException { get; }
    Property Value
    Type Description
    Exception
    View Source

    Description

    Gets text describing a constraint

    Declaration
    public override string Description { get; }
    Property Value
    Type Description
    string
    Overrides
    PrefixConstraint.Description

    Methods

    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 override Task<ConstraintResult> ApplyToAsync<TActual>(Func<Task<TActual>> actual)
    Parameters
    Type Name Description
    Func<Task<TActual>> actual
    Returns
    Type Description
    Task<ConstraintResult>
    Type Parameters
    Name Description
    TActual
    Overrides
    Constraint.ApplyToAsync<TActual>(Func<Task<TActual>>)
    View Source

    ApplyTo<TActual>(ActualValueDelegate<TActual>)

    Converts an ActualValueDelegate to a TestDelegate before calling the primary overload.

    Declaration
    public override ConstraintResult ApplyTo<TActual>(ActualValueDelegate<TActual> del)
    Parameters
    Type Name Description
    ActualValueDelegate<TActual> del
    Returns
    Type Description
    ConstraintResult
    Type Parameters
    Name Description
    TActual
    Overrides
    Constraint.ApplyTo<TActual>(ActualValueDelegate<TActual>)
    View Source

    ApplyTo<TActual>(TActual)

    Executes the code of the delegate and captures any exception. If a non-null base constraint was provided, it applies that constraint to the exception.

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

    A delegate representing the code to be tested

    Returns
    Type Description
    ConstraintResult

    True if an exception is thrown and the constraint succeeds, otherwise false

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

    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