public void Test_Times_Onces() { // Arrange var formatter = new ErrorFormatter(); var expected = new ExpectedCall { Arguments = new ArgumentValue[] {new SingleArgumentValue(1), }, CallExpression = "SomeMethod(foo)", Method = GetType().GetMethods().First(), Times = Times.Once() }; var observedCalls = new List<ObservedCall> { new ObservedCall(GetType().GetMethods().First(), new object[]{1}) }; // Act string error = formatter.FormatVerifyError(expected, 0, observedCalls); Console.WriteLine("Error: {0}", error); Assert.That(error, Is.StringContaining("SomeMethod(foo)"), "Error should contain expected call expression."); Assert.That(error, Is.StringContaining("Test_Times_Once"), "Error should contain actual call."); }
string IErrorFormatter.FormatVerifyError(ExpectedCall expected, int actualCalls, ICollection<ObservedCall> actual) { Contract.Requires(expected != null, "expected should not be null."); Contract.Requires(actual != null, "actual should not be null."); Contract.Ensures(Contract.Result<string>() != null); throw new NotImplementedException(); }
public string FormatVerifyError(ExpectedCall expected, int actualCalls, ICollection<ObservedCall> actual) { var sb = new StringBuilder(); sb.AppendFormat("Expected invocation on the mock {0}, but was {1}.", expected.Times, TimesToString(actualCalls)) .AppendLine() .AppendFormat("Expected call: {0}", expected.CallExpression) .AppendLine().AppendLine(); sb.AppendLine("Actual calls:"); PerformedActionsToString(sb, actual); return sb.ToString(); }
public void Verify(ExpectedCall expected, ICollection<ObservedCall> actual) { Contract.Requires(expected != null, "expected should not be null."); Contract.Requires(actual != null, "actual should not be null."); var mismatches = GetExpectedMismatches(new []{expected}, actual); var firstMismatch = mismatches.FirstOrDefault(); if (firstMismatch != null) { string error = _errorFormatter.FormatVerifyError(firstMismatch.ExpectedCall, firstMismatch.Matches, firstMismatch.ObservedCalls); throw new VerificationException(error); } }
public void Setup() { // Arrange var expression = (Expression<Action<ILogger>>)(l => l.Write()); var parser = new ExpressionsParser(); // Act _expectedCall = parser.Parse(expression); }
public static Match MatchCall(ExpectedCall expected, IList<ObservedCall> actual) { int matches = actual.Count(e => expected.MatchArguments(e.Arguments)); bool matched = expected.Times.Match(matches); return new Match { IsMatched = matched, Matches = matches, ActualCalls = matches, ExpectedCall = expected, ObservedCalls = actual, }; }