Throws
Helper class with properties and methods that supply
constraints that operate on exceptions.
using NUnit.Framework.Constraints;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace NUnit.Framework
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public abstract class Throws
{
public static ResolvableConstraintExpression Exception => new ConstraintExpression().Append((SelfResolvingOperator)new ThrowsOperator());
public static ResolvableConstraintExpression InnerException => Exception.InnerException;
public static ExactTypeConstraint TargetInvocationException => TypeOf(typeof(TargetInvocationException));
public static ExactTypeConstraint ArgumentException => TypeOf(typeof(ArgumentException));
public static ExactTypeConstraint ArgumentNullException => TypeOf(typeof(ArgumentNullException));
public static ExactTypeConstraint InvalidOperationException => TypeOf(typeof(InvalidOperationException));
public static ThrowsNothingConstraint Nothing => new ThrowsNothingConstraint();
public static ExactTypeConstraint TypeOf(Type expectedType)
{
return Exception.TypeOf(expectedType);
}
public static ExactTypeConstraint TypeOf<[System.Runtime.CompilerServices.Nullable(0)] TExpected>() where TExpected : Exception
{
return TypeOf(typeof(TExpected));
}
public static InstanceOfTypeConstraint InstanceOf(Type expectedType)
{
return Exception.InstanceOf(expectedType);
}
public static InstanceOfTypeConstraint InstanceOf<[System.Runtime.CompilerServices.Nullable(0)] TExpected>() where TExpected : Exception
{
return InstanceOf(typeof(TExpected));
}
}
}