/// <summary> /// Asserts that a particular method was NOT called on this mock object that match /// a particular constraint set. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="mock">The mock.</param> /// <param name="action">The action.</param> /// <param name="setupConstraints">The setup constraints.</param> public static void AssertWasNotCalled <T>(this T mock, Action <T> action, Action <IMethodOptions <object> > setupConstraints) { ExpectationVerificationInformation verificationInformation = GetExpectationsToVerify(mock, action, setupConstraints); foreach (var args in verificationInformation.ArgumentsForAllCalls) { if (verificationInformation.Expected.IsExpected(args)) { throw new ExpectationViolationException("Expected that " + verificationInformation.Expected.ErrorMessage + " would not be called, but it was found on the actual calls made on the mocked object."); } } }
/// <summary> /// Asserts that a particular method was called on this mock object that match /// a particular constraint set. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="mock">The mock.</param> /// <param name="action">The action.</param> /// <param name="setupConstraints">The setup constraints.</param> public static void AssertWasCalled <T>(this T mock, Action <T> action, Action <IMethodOptions <object> > setupConstraints) { ExpectationVerificationInformation verificationInformation = GetExpectationsToVerify(mock, action, setupConstraints); foreach (var args in verificationInformation.ArgumentsForAllCalls) { if (verificationInformation.Expected.IsExpected(args)) { verificationInformation.Expected.AddActualCall(); } } if (verificationInformation.Expected.ExpectationSatisfied) { return; } throw new ExpectationViolationException(verificationInformation.Expected.BuildVerificationFailureMessage()); }