示例#1
0
            public override TestFailure Should(ITestMatcher <T> matcher)
            {
                var s          = Stopwatch.StartNew();
                var durationMS = (int)_duration.TotalMilliseconds;

                do
                {
                    var aFailure = _inner.Should(matcher);
                    if (aFailure != null)
                    {
                        var result = new TestFailure("spec.consistently")
                        {
                            Message  = SR.ConsistentlyElapsedBefore(((Time)_duration).ToString("n")),
                            Children =
                            {
                                TestMatcherLocalizer.FailurePredicate(matcher)
                            },
                        };
                        result.UserData.CopyActuals(aFailure.UserData);
                        return(result);
                    }
                } while (s.ElapsedMilliseconds <= durationMS);

                return(null);
            }
示例#2
0
            protected override TestFailure ShouldCore(IEnumerable <object> items, ITestMatcher <object> baseMatcher)
            {
                var tally = Tally.New(items,
                                      Matchers.Not(baseMatcher),
                                      t => (t.Failures == 5),
                                      TestMatcherLocalizer.FailurePredicate(baseMatcher));

                return(tally.Lift("notAny", SR.ExpectedNotAnyElementTo()));
            }
示例#3
0
            protected override TestFailure ShouldCore(IEnumerable <object> items, ITestMatcher <object> baseMatcher)
            {
                var tally = Tally.New(items,
                                      Matchers.Not(baseMatcher),
                                      t => (t.Successes > 0),
                                      TestMatcherLocalizer.FailurePredicate(baseMatcher));

                if (tally.Successes > 0)
                {
                    return(null);
                }
                return(tally.Lift("notAll", SR.ExpectedNotAllElementsTo()));
            }
示例#4
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);
            }
示例#5
0
            public static Tally New <T>(
                IEnumerable <T> items,
                ITestMatcher <T> matcher,
                Predicate <Tally> stop,
                TestFailure predicateFailure = null)
            {
                if (stop == null)
                {
                    stop = _ => false;
                }
                if (predicateFailure == null)
                {
                    predicateFailure = TestMatcherLocalizer.FailurePredicate(matcher);
                }

                var result = new Tally();

                result.Indexes = new List <int>();
                int index = 0;

                foreach (var item in items)
                {
                    if (stop(result))
                    {
                        result.Stopped = true;
                        break;
                    }

                    var matches = matcher.Matches(TestActual.Value(item));

                    if (matches)
                    {
                        result.Successes++;
                    }
                    else
                    {
                        result.Failures++;
                        result.Indexes.Add(index);
                        result.AFailure = predicateFailure;
                    }

                    index++;
                }
                return(result);
            }