/// <summary> /// 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. /// </summary> /// <param name="actual">A delegate representing the code to be tested</param> /// <returns>True if an exception is thrown and the constraint succeeds, otherwise false</returns> public override ConstraintResult ApplyTo <TActual>(TActual actual) { //TestDelegate code = actual as TestDelegate; //if (code == null) // throw new ArgumentException( // string.Format("The actual value must be a TestDelegate but was {0}", actual.GetType().Name), "actual"); //caughtException = null; //try //{ // code(); //} //catch (Exception ex) //{ // caughtException = ex; //} caughtException = ExceptionInterceptor.Intercept(actual); return(new ThrowsConstraintResult( this, caughtException, caughtException != null ? baseConstraint.ApplyTo(caughtException) : null)); }
/// <summary> /// 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. /// </summary> /// <param name="actual">A delegate representing the code to be tested</param> /// <returns>True if an exception is thrown and the constraint succeeds, otherwise false</returns> public override bool Matches(object actual) { caughtException = ExceptionInterceptor.Intercept(actual); if (caughtException == null) { return(false); } return(baseConstraint == null || baseConstraint.Matches(caughtException)); }
/// <summary> /// Test whether the constraint is satisfied by a given value /// </summary> /// <param name="actual">The value to be tested</param> /// <returns>True if no exception is thrown, otherwise false</returns> public override bool Matches(object actual) { caughtException = ExceptionInterceptor.Intercept(actual); return(caughtException == null); }