Esempio n. 1
0
            protected override TestFailure ShouldCore(IEnumerable <object> items, ITestMatcher <object> baseMatcher)
            {
                if (ShouldVerify)
                {
                    if (_max < _min)
                    {
                        throw SpecFailure.CardinalityMinGreaterThanMax();
                    }
                    if (_min < 0 || _max < 0)
                    {
                        throw SpecFailure.NegativeCardinality();
                    }
                }
                if (!_min.HasValue && !_max.HasValue)
                {
                    return(null);
                }

                Predicate <Tally> stopper = null;

                if (_max.HasValue)
                {
                    stopper = t => t.Successes > _max;
                }

                var  tally      = Tally.New(items, baseMatcher, stopper);
                bool outOfRange = (_max.HasValue && tally.Successes > _max.Value) ||
                                  (_min.HasValue && tally.Successes < _min.Value);

                if (_outer)
                {
                    outOfRange = !outOfRange;
                }

                if (outOfRange)
                {
                    string message = Message();
                    tally.AFailure = TestMatcherLocalizer.FailurePredicate(baseMatcher);

                    if (tally.AFailure.Message == "")
                    {
                        tally.AFailure = null;
                        message        = message.Replace("to:", "items");
                    }

                    return(tally.Lift("cardinality", message, true));
                }

                return(null);
            }