예제 #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>
        /// 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);
        }