コード例 #1
0
        /// <summary>
        /// Used to test exception messages
        /// </summary>
        /// <param name="src">Continuation containing exception message to test</param>
        /// <param name="test">Custom function to test the message -- return true if the test should pass</param>
        /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
        /// <returns>Another continuation so you can do .And()</returns>
        public static IStringPropertyContinuation Matching(
            this IExceptionPropertyContinuation <string> src,
            Func <string, bool> test,
            Func <string> customMessageGenerator)
        {
            var result = ContinuationFactory.Create <string, StringPropertyContinuation>(
                null,
                src as IExpectationContext <string>
                );

            src.AddMatcher(
                s =>
            {
                result.Actual = s;
                var passed    = test(s);
                return(new MatcherResult(
                           passed,
                           MessageForMatchResult(
                               passed,
                               s,
                               customMessageGenerator
                               )
                           ));
            });
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Add a matcher onto an Exception property continuation
 /// </summary>
 /// <param name="continuation">Continuation to add matcher to</param>
 /// <param name="matcher">Matcher to run</param>
 /// <typeparam name="T">Type of the object under test</typeparam>
 public static void AddMatcher <T>(
     this IExceptionPropertyContinuation <T> continuation,
     Func <string, IMatcherResult> matcher
     )
 {
     AddMatcherPrivate(continuation, matcher);
 }
コード例 #3
0
 /// <summary>
 /// Used to test exception messages
 /// </summary>
 /// <param name="src">Continuation containing exception message to test</param>
 /// <param name="test">Custom function to test the message -- return true if the test should pass</param>
 /// <param name="customMessage">Custom message to add to failure messages</param>
 /// <returns>Another continuation so you can do .And()</returns>
 public static IStringPropertyContinuation Matching(
     this IExceptionPropertyContinuation <string> src,
     Func <string, bool> test,
     string customMessage)
 {
     return(src.Matching(test, () => customMessage));
 }
コード例 #4
0
 /// <summary>
 /// Used to test exception messages
 /// </summary>
 /// <param name="src">Continuation containing exception message to test</param>
 /// <param name="test">Custom function to test the message -- return true if the test should pass</param>
 /// <returns>Another continuation so you can do .And()</returns>
 public static IStringPropertyContinuation Matching(
     this IExceptionPropertyContinuation <string> src,
     Func <string, bool> test
     )
 {
     return(src.Matching(test, NULL_STRING));
 }
コード例 #5
0
        /// <summary>
        /// Used to test exception messages
        /// </summary>
        /// <param name="src">Continuation carrying an exception message</param>
        /// <param name="search">String to look for in the message</param>
        /// <param name="customMessageGenerator">Generates a custom message to add to a failure message</param>
        /// <returns>Another continuation so you can do .And() on it</returns>
        public static IStringPropertyContinuation Containing(
            this IExceptionPropertyContinuation <string> src,
            string search,
            Func <string> customMessageGenerator)
        {
            var result = ContinuationFactory.Create <string, StringPropertyContinuation>(
                null,
                src as IExpectationContext <string>
                );

            src.AddMatcher(
                s =>
            {
                result.Actual  = s;
                var nextOffset = s?.IndexOf(search) ?? -1;
                if (nextOffset > -1)
                {
                    nextOffset += search?.Length ?? 0;
                }
                result.SetMetadata(SEARCH_OFFSET, nextOffset);

                var passed = nextOffset > -1;
                return(new MatcherResult(
                           passed,
                           MessageForContainsResult(
                               passed,
                               s,
                               search,
                               customMessageGenerator
                               )
                           ));
            });
            return(result);
        }
コード例 #6
0
 /// <summary>
 /// Used to test exception messages
 /// </summary>
 /// <param name="src">Continuation carrying an exception message</param>
 /// <param name="search">String to look for in the message</param>
 /// <param name="customMessage">Custom message to add to a failure message</param>
 /// <returns>Another continuation so you can do .And() on it</returns>
 public static IStringPropertyContinuation Containing(
     this IExceptionPropertyContinuation <string> src,
     string search,
     string customMessage)
 {
     return(src.Containing(search, () => customMessage));
 }
コード例 #7
0
 /// <summary>
 /// Used to test exception messages
 /// </summary>
 /// <param name="src">Continuation carrying an exception message</param>
 /// <param name="search">String to look for in the message</param>
 /// <returns>Another continuation so you can do .And() on it</returns>
 public static IStringPropertyContinuation Containing(
     this IExceptionPropertyContinuation <string> src,
     string search)
 {
     return(src.Containing(search, NULL_STRING));
 }