ThrowsNothingConstraint
ThrowsNothingConstraint tests that a delegate does not
throw an exception.
using NUnit.Framework.Internal;
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class ThrowsNothingConstraint : Constraint
{
public override string Description => "No Exception to be thrown";
public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(TActual actual)
{
Delegate parameterlessDelegate = ConstraintUtils.RequireActual<Delegate>(actual, "actual", false);
Exception ex = ExceptionHelper.RecordException(parameterlessDelegate, "actual");
return new ConstraintResult(this, ex, ex == null);
}
public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(ActualValueDelegate<TActual> del)
{
return ApplyTo((Delegate)del);
}
public ThrowsNothingConstraint()
: base(Array.Empty<object>())
{
}
}
}