Esempio n. 1
0
        /// <summary>
        /// Tests if the value under test contains a given string. May be continued
        /// with ".And"
        /// </summary>
        /// <param name="continuation">Continuation to act on</param>
        /// <param name="search">String value to search for</param>
        /// <param name="customMessage">Custom message to include in failure messages</param>
        /// <returns>IStringContainContinuation onto which you can chain .And</returns>
        public static IStringMore Contain(
            this ICanAddMatcher <string> continuation,
            string search,
            Func <string> customMessage
            )
        {
            var result = new StringContainContinuation(continuation);

            AddContainsMatcherTo(continuation, search, customMessage, result);
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Continue testing a string for another substring from beyond the end of the last match
        /// </summary>
        /// <param name="continuation">Continuation to operate on</param>
        /// <param name="search">String to search for</param>
        /// <param name="customMessageGenerator">Generates a custom message to include in failure messages</param>
        /// <returns></returns>
        public static IStringMore Then(
            this IStringContainContinuation continuation,
            string search,
            Func <string> customMessageGenerator
            )
        {
            var result = new StringContainContinuation(continuation);

            AddContainsMatcherTo(continuation, search, customMessageGenerator, result);
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Provides the .Then(...) extension on already extended string
        /// continuations.
        /// </summary>
        /// <param name="more">Continuation to operate on</param>
        /// <param name="search">String to search for</param>
        /// <param name="customMessageGenerator">Generates a custom message to add to failure messages</param>
        /// <returns></returns>
        public static IStringMore Then(
            this IStringMore more,
            string search,
            Func <string> customMessageGenerator
            )
        {
            var canAddMatcher = more as ICanAddMatcher <string>;
            var result        = new StringContainContinuation(canAddMatcher);

            AddContainsMatcherTo(canAddMatcher, search, customMessageGenerator, result);
            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Continue testing a string for another substring
        /// </summary>
        /// <param name="continuation">Existing continuation fron a Contain()</param>
        /// <param name="search">string to search for</param>
        /// <param name="customMessageGenerator">Generates a custom message to include in failure messages</param>
        /// <returns>IStringContainContinuation onto which you can chain .And</returns>
        public static IStringMore And(
            this IStringMore continuation,
            string search,
            Func <string> customMessageGenerator
            )
        {
            var result = new StringContainContinuation(continuation);

            continuation.SetMetadata(SEARCH_OFFSET, 0); // And will reset the offset -- it's not ordered
            AddContainsMatcherTo(continuation, search, customMessageGenerator, result);
            return(result);
        }
Esempio n. 5
0
        private static void AddContainsMatcherTo(
            ICanAddMatcher <string> continuation,
            string search,
            Func <string> customMessage,
            StringContainContinuation next
            )
        {
            continuation.AddMatcher(
                s =>
            {
                var priorOffset = continuation.GetMetadata <int>(SEARCH_OFFSET);
                var nextOffset  = GetNextOffsetOf(search, s, priorOffset);

                next.SetMetadata(SEARCH_OFFSET, nextOffset);

                var passed = nextOffset > -1;
                return(new MatcherResult(
                           passed,
                           () =>
                {
                    var offsetMessage = priorOffset > 0
                                ? $" after index {priorOffset}"
                                : "";
                    return FinalMessageFor(
                        () => new[]
                    {
                        "Expected",
                        s.Stringify(),
                        $"{passed.AsNot()}to contain",
                        search.Stringify(),
                        offsetMessage
                    },
                        customMessage
                        );
                }
                           ));
            });
        }