ThrowsExceptionConstraint
ThrowsExceptionConstraint tests that an exception has
            been thrown, without any further tests.
            
                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 ThrowsExceptionConstraint : Constraint
    {
        [System.Runtime.CompilerServices.Nullable(0)]
        private class ThrowsExceptionConstraintResult : ConstraintResult
        {
            public ThrowsExceptionConstraintResult(ThrowsExceptionConstraint constraint, [System.Runtime.CompilerServices.Nullable(2)] Exception caughtException)
                : base(constraint, caughtException, caughtException != null)
            {
            }
            public override void WriteActualValueTo(MessageWriter writer)
            {
                if (base.Status == ConstraintStatus.Failure)
                    writer.Write("no exception thrown");
                else
                    base.WriteActualValueTo(writer);
            }
        }
        public override string Description => "an 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 caughtException = ExceptionHelper.RecordException(parameterlessDelegate, "actual");
            return new ThrowsExceptionConstraintResult(this, caughtException);
        }
        public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(ActualValueDelegate<TActual> del)
        {
            return ApplyTo((Delegate)del);
        }
        public ThrowsExceptionConstraint()
            : base(Array.Empty<object>())
        {
        }
    }
}