public CountMatchContinuationOfStringCollectionVerb(
     ICountMatchContinuation <IEnumerable <string> > wrapped,
     CountMatchMethods method,
     int expectedCount
     ) : base(wrapped, method, expectedCount)
 {
 }
        public static int GetExpectedCount <T>(
            this ICountMatchContinuation <T> continuation
            )
        {
            var actual = continuation as CountMatchContinuation <T>;

            if (actual != null)
            {
                return(actual.ExpectedCount);
            }
            return(continuation.TryGetPropertyValue <int?>("ExpectedCount") ?? 0);
        }
        public static CountMatchMethods GetCountMatchMethod <T>(
            this ICountMatchContinuation <T> continuation
            )
        {
            var actual = continuation as CountMatchContinuation <T>;

            if (actual != null)
            {
                return(actual.CountMatchMethod);
            }
            return(continuation.TryGetPropertyValue <CountMatchMethods>("CountMatchMethod"));
        }
Exemplo n.º 4
0
 public static IMore <IEnumerable <int> > Odds(this ICountMatchContinuation <IEnumerable <int> > continuation)
 {
     return(continuation.AddMatcher(collection =>
     {
         return TestCollection(
             collection,
             continuation.ExpectedCount,
             continuation.GetCountMatchMethod(),
             i => i % 2 == 1,
             passed => $"Expected {collection.LimitedPrint()} {passed.AsNot()}to be only odd numbers"
             );
     }));
 }
        /// <summary>
        /// Acting on a continuation, will return the Method for that
        /// continuation, either directly by casting to the internal concrete
        /// implementation, or, if you have your own implementation, looking, via
        /// reflection for the Method property as an integer.
        /// Use like: var method = {continuation}.GetCountMatchMethod();
        /// </summary>
        /// <param name="continuation">Continuation to act on.</param>
        /// <typeparam name="T">Underlying type of the continuation.</typeparam>
        /// <returns></returns>
        public static CountMatchMethods GetCountMatchMethod <T>(
            this ICountMatchContinuation <T> continuation
            )
        {
            switch (continuation)
            {
            case CountMatchContinuation <T> countMatch:
                return(countMatch.Method);

            default:
                return(continuation.TryGetPropertyValue <CountMatchMethods?>(
                           nameof(CountMatchContinuation <T> .Method)) ??
                       CountMatchMethods.Exactly);
            }
        }
Exemplo n.º 6
0
 public static void Odds(this ICountMatchContinuation <IEnumerable <int> > continuation)
 {
     continuation.AddMatcher(collection =>
     {
         var expectedCount = continuation.ExpectedCount;
         var method        = continuation.GetCountMatchMethod();
         // TODO: use count and method
         var count  = collection.Count(i => i % 2 == 1);
         var total  = collection.Count();
         var passed = _strategies[method](total, count, expectedCount);
         return(new MatcherResult(
                    passed,
                    () => $"Expected {collection.LimitedPrint()} {passed.AsNot()}to be only odd numbers"
                    ));
     });
 }
 public static void Odds(this ICountMatchContinuation <IEnumerable <int> > continuation)
 {
     continuation.AddMatcher(collection =>
     {
         var expectedCount = continuation.GetExpectedCount();
         var method        = continuation.GetCountMatchMethod();
         // TODO: use count and method
         var count  = collection.Count(i => i % 2 == 1);
         var total  = collection.Count();
         var passed = _strategies[method](total, count, expectedCount);
         var not    = passed ? "" : "not ";
         return(new MatcherResult(
                    passed,
                    $"Expected {MessageHelpers.CollectionPrint(collection)} {not}to be only odd numbers"
                    ));
     });
 }
Exemplo n.º 8
0
 public static void Birds <T>(this ICountMatchContinuation <IEnumerable <T> > continuation)
 {
     continuation.AddMatcher(collection =>
     {
         var expectedCount = continuation.GetExpectedCount <T>();
         var matchMethod   = continuation.GetCountMatchMethod();
         var total         = collection.Count();
         var count         = collection.Count(o => o is Flamingo || o is Penguin);
         var passed        = _strategies[matchMethod](total, count, expectedCount);
         var not           = passed
             ? ""
             : "not ";
         return(new MatcherResult(
                    passed,
                    $"Expected {not}to match {_messages[matchMethod](expectedCount)} Birds"
                    ));
     });
 }