static TestFailure FailureMessageCore(object matcher, bool predicate) { var matcherName = TestMatcherName.For(matcher); if (predicate) { matcherName = matcherName.Predicate(); } // We use the actual matcher to get the user data for the failure var failure = new TestFailure(matcherName, ActualMatcher(matcher)); string message = ExpectedMessage(matcherName, failure.UserData); failure.Message = message; ChildrenMessages(failure, matcher); return(failure); }
public static TestFailure Failure(object matcher, object actual) { TestFailure failure = FailureMessageCore(matcher, false); failure.UserData.Add("Actual", actual); if (matcher is ITestMatcherActualDiff diff) { var patch = diff.GetPatch(actual); if (patch != null) { if (patch.ALineCount > 1 || patch.BLineCount > 1) { failure.UserData.Diff = patch; } } } return(failure); }
public static void RunTestAndExpect(IEnumerable tests, int expFailures, bool checkException ) { TestResult result = new TestResult(); new TestRunner(tests).Run(result); if (expFailures != result.Failures.Count) { Assert.Fail(result.Failures.ToString()); } if (checkException) { for (IEnumerator iter = result.Failures.GetEnumerator(); iter.MoveNext();) { TestFailure failure = (TestFailure)iter.Current; Assert.AreEqual(Exception, failure.Reason); } } }
public override TestFailure Should(ITestMatcher <T> matcher) { var s = Stopwatch.StartNew(); var durationMS = (int)_duration.TotalMilliseconds; TestFailure aFailure = null; while (s.ElapsedMilliseconds <= durationMS) { aFailure = _inner.Should(matcher); if (aFailure == null) { return(null); } } var result = new TestFailure("spec.eventually") { Message = SR.EventuallyTimedOutAfter(((Time)_duration).ToString("n")), Children = { TestMatcherLocalizer.FailurePredicate(matcher) }, }; result.UserData.CopyActuals(aFailure.UserData); return(result); }
/// <summary> /// Create a new TestFailure object. /// </summary> /// <param name="ID">Initial value of Id.</param> /// <param name="testId">Initial value of TestId.</param> /// <param name="changed">Initial value of Changed.</param> public static TestFailure CreateTestFailure(int ID, int testId, global::System.DateTimeOffset changed) { TestFailure testFailure = new TestFailure(); testFailure.Id = ID; testFailure.TestId = testId; testFailure.Changed = changed; return testFailure; }
public AssertException(string userMessage, TestFailure failure, Exception innerException) : base(failure.FormatMessage(userMessage), innerException) { UserMessage = userMessage; TestFailure = failure; }