コード例 #1
0
 /// <summary>
 /// Assert that the provided code throws an exception of the given type
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected exception type</param>
 /// <param name="customMessage">Custom message to include when this expectation fails</param>
 /// <returns>Fluency extension</returns>
 public static IThrowAndContinuation <Exception> Type(
     this IWithAfterThrowContinuation <Exception> continuation,
     Type expected,
     string customMessage)
 {
     return(continuation.Type(expected, () => customMessage));
 }
コード例 #2
0
        /// <summary>
        /// Assert that the provided code throws an exception of the given type
        /// </summary>
        /// <param name="continuation">Continuation to operate on</param>
        /// <param name="expected">Expected exception type</param>
        /// <param name="customMessageGenerator">Generates a custom message to include when this expectation fails</param>
        /// <returns>Fluency extension</returns>
        public static IThrowAndContinuation <Exception> Type(
            this IWithAfterThrowContinuation <Exception> continuation,
            Type expected,
            Func <string> customMessageGenerator)
        {
            var result = new ThrowAndContinuation <Exception>();

            result.SetParent(continuation as IExpectationContext <Exception>);
            continuation.AddMatcher(actual =>
            {
                result.Exception = actual;
                var passed       = actual.GetType() == expected;
                return(new MatcherResult(
                           passed,
                           FinalMessageFor(
                               () => $"Expected to throw an exception of type {expected} but received {actual}",
                               customMessageGenerator)
                           ));
            });
            return(result);
        }
コード例 #3
0
 /// <summary>
 /// Assert that the provided code throws an exception of the given type
 /// </summary>
 /// <param name="continuation">Continuation to operate on</param>
 /// <param name="expected">Expected exception type</param>
 /// <returns>Fluency extension</returns>
 public static IThrowAndContinuation <Exception> Type(
     this IWithAfterThrowContinuation <Exception> continuation,
     Type expected)
 {
     return(continuation.Type(expected, null as string));
 }