public sealed override TestFailure Should(ITestMatcher <object> matcher) { _real = matcher; var _ = _inner.Should(this); return(Result); }
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")); }
public CastProvider(ITestMatcher <T> real) { _real = real; // Don't be reentrant with the cast provider type itself Debug.Assert(!_real.GetType().Name.Contains("CastProvider")); }
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")); }
public ExpectedAccessorData(string name, object specified, ITestMatcher <object> matcher, IMemberAccessor accessor) { Name = name; Specified = specified; Matcher = matcher; Accessor = accessor; }
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)); }
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")); }
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())); }
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())); }
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); }
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())); }
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); }
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); }
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); }
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); }
public void Like(ITestMatcher matcher, string message = null, object[] args = null) { _cmd.Should(matcher, message, args); }
public override TestFailure Should(ITestMatcher <T> matcher) { return(_inner.Should(new CastProvider(matcher))); }
public void Like(ITestMatcher <IEnumerable> matcher, string message = null, object[] args = null) { _cmd.Should(matcher, message, (object[])args); }
private static NullExampleData RequiresValidationButPasses <T>(ITestMatcher <T> matcher) { return(new NullExampleData(typeof(T), matcher, NullMode.RequiresValidationButPasses)); }
public static NotMatcher Not(ITestMatcher matcher) { return(new NotMatcher(matcher)); }
public static NotMatcher <T> Not <T>(ITestMatcher <T> matcher) { return(new NotMatcher <T>(matcher)); }
public static bool Matches(this ITestMatcher self, Action testCode) { return(self.Matches( TestActual.Of(Unit.Thunk(testCode)) )); }
public void Like(ITestMatcher matcher, string message, params object[] args) { _cmd.Should(matcher, message, (object[])args); }
internal static bool Matches <T>(this ITestMatcher <T> self, Func <T> actualFactory) { return(self.Matches(new TestActual <T>(actualFactory))); }
public void To(ITestMatcher matcher, string message = null, params object[] args) { _cmd.Should(matcher, message, args); }