Class ThrowsConstraint
ThrowsConstraint is used to test the exception thrown by a delegate by applying a constraint to it.
Inherited Members
Namespace: NUnit.Framework.Constraints
Assembly: nunit.framework.dll
Syntax
public class ThrowsConstraint : PrefixConstraint, IConstraint, IResolveConstraint
Constructors
View SourceThrowsConstraint(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 SourceActualException
Get the actual exception thrown - used by Assert.Throws.
Declaration
public Exception? ActualException { get; }
Property Value
Type | Description |
---|---|
Exception |
Description
Gets text describing a constraint
Declaration
public override string Description { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
Methods
View SourceApplyTo<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
View SourceApplyTo<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 |