Ejemplo n.º 1
0
            public sealed override TestFailure Should(ITestMatcher <object> matcher)
            {
                _real = matcher;
                var _ = _inner.Should(this);

                return(Result);
            }
Ejemplo n.º 2
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);
            }
                public CaptureProvider(ITestMatcher <Exception> real)
                {
                    _real = real;

                    // Don't be reentrant with the provider type itself
                    Debug.Assert(!_real.GetType().Name.Contains("CaptureProvider"));
                }
Ejemplo n.º 4
0
                public CastProvider(ITestMatcher <T> real)
                {
                    _real = real;

                    // Don't be reentrant with the cast provider type itself
                    Debug.Assert(!_real.GetType().Name.Contains("CastProvider"));
                }
Ejemplo n.º 5
0
                public ItemsProvider(ITestMatcher <IEnumerable <object> > real)
                {
                    _real = real;

                    // Don't be reentrant with the cast provider type itself
                    Debug.Assert(!_real.GetType().Name.Contains("ItemsProvider"));
                }
Ejemplo n.º 6
0
 public ExpectedAccessorData(string name, object specified, ITestMatcher <object> matcher, IMemberAccessor accessor)
 {
     Name      = name;
     Specified = specified;
     Matcher   = matcher;
     Accessor  = accessor;
 }
Ejemplo n.º 7
0
            protected override TestFailure ShouldCore(IEnumerable <object> items,
                                                      ITestMatcher <object> baseMatcher
                                                      )
            {
                var tally = Tally.New(items, baseMatcher, t => (t.Failures == 5));

                return(tally.Lift("all", SR.ExpectedAllElementsTo()));
            }
 public override TestFailure Should(ITestMatcher <T> matcher)
 {
     if (_comparer != null)
     {
         matcher = ((ITestMatcherWithComparer <T>)matcher).WithComparer(_comparer);
     }
     return(_inner.Should(matcher));
 }
Ejemplo n.º 9
0
 public NotMatcher(ITestMatcher <T> matcher)
 {
     if (matcher == null)
     {
         throw new ArgumentNullException("matcher");
     }
     _matcher = matcher;
 }
                public PropertyProvider(PropertyCommand <T, TProperty> parent, ITestMatcher <TProperty> real)
                {
                    _parent = parent;
                    _real   = real;

                    // Don't be reentrant with the cast provider type itself
                    Debug.Assert(!_real.GetType().Name.Contains("PropertyProvider"));
                }
Ejemplo n.º 11
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()));
            }
Ejemplo n.º 12
0
            protected override TestFailure ShouldCore(IEnumerable <object> items, ITestMatcher <object> baseMatcher)
            {
                var tally = Tally.New(items, baseMatcher, t => (t.Successes > 0));

                if (tally.Successes > 0)
                {
                    return(null);
                }
                return(tally.Lift("any", SR.ExpectedAnyElementTo()));
            }
Ejemplo n.º 13
0
        internal static void Should <T>(this ExpectationCommand <T> self, ITestMatcher <T> matcher, string message = null, object[] args = null)
        {
            var failure = self.Should(matcher);

            if (failure != null)
            {
                AsserterBehavior behavior = failure.AsserterBehavior;
                behavior.Assert(failure.UpdateTestSubject().UpdateMessage(message, args));
            }
        }
            public override TestFailure Should(ITestMatcher <Exception> matcher)
            {
                var pp      = new CaptureProvider(matcher);
                var failure = _inner.Should(pp);

                if (failure != null)
                {
                    failure.UpdateActual(pp.Actual.Value);
                }
                return(failure);
            }
            public override TestFailure Should(ITestMatcher <TProperty> matcher)
            {
                var pp      = new PropertyProvider(this, matcher);
                var failure = _inner.Should(pp);

                if (failure != null)
                {
                    failure.UpdateActual(pp.Actual.Value);
                    failure.UserData["Property"] = _name;
                }
                return(failure);
            }
Ejemplo n.º 16
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()));
            }
Ejemplo n.º 17
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);
            }
Ejemplo n.º 18
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);
            }
Ejemplo n.º 19
0
            public override TestFailure Should(ITestMatcher <T> matcher)
            {
                var actual = TestActual.Of(_thunk);

                if (_negated)
                {
                    matcher = Matchers.Not(matcher);
                }
                if (matcher.Matches(actual))
                {
                    return(null);
                }

                var result = TestMatcherLocalizer.Failure(matcher, actual.Value)
                             .UpdateGiven(_given)
                             .UpdateBehavior(_behavior);

                if (matcher is ITestMatcher <Unit> m)
                {
                    result.UpdateActual(DisplayActual.Exception(actual.Exception));
                }
                return(result);
            }
Ejemplo n.º 20
0
 public static void ToNot <T>(this IExpectationBuilderAsserter <T> self, ITestMatcher <object> matcher, string message = null, params object[] args)
 {
     self.To(Not(matcher), message, (object[])args);
 }
Ejemplo n.º 21
0
 public void Like(ITestMatcher matcher, string message = null, object[] args = null)
 {
     _cmd.Should(matcher, message, args);
 }
Ejemplo n.º 22
0
 public override TestFailure Should(ITestMatcher <T> matcher)
 {
     return(_inner.Should(new CastProvider(matcher)));
 }
Ejemplo n.º 23
0
 public void Like(ITestMatcher <IEnumerable> matcher, string message = null, object[] args = null)
 {
     _cmd.Should(matcher, message, (object[])args);
 }
Ejemplo n.º 24
0
 private static NullExampleData RequiresValidationButPasses <T>(ITestMatcher <T> matcher)
 {
     return(new NullExampleData(typeof(T), matcher, NullMode.RequiresValidationButPasses));
 }
Ejemplo n.º 25
0
 public static NotMatcher Not(ITestMatcher matcher)
 {
     return(new NotMatcher(matcher));
 }
Ejemplo n.º 26
0
 public static NotMatcher <T> Not <T>(ITestMatcher <T> matcher)
 {
     return(new NotMatcher <T>(matcher));
 }
Ejemplo n.º 27
0
 public static bool Matches(this ITestMatcher self, Action testCode)
 {
     return(self.Matches(
                TestActual.Of(Unit.Thunk(testCode))
                ));
 }
Ejemplo n.º 28
0
 public void Like(ITestMatcher matcher, string message, params object[] args)
 {
     _cmd.Should(matcher, message, (object[])args);
 }
Ejemplo n.º 29
0
 internal static bool Matches <T>(this ITestMatcher <T> self, Func <T> actualFactory)
 {
     return(self.Matches(new TestActual <T>(actualFactory)));
 }
Ejemplo n.º 30
0
 public void To(ITestMatcher matcher, string message = null, params object[] args)
 {
     _cmd.Should(matcher, message, args);
 }