/// <summary> /// Retrieve next expectation and remove from FIFO. /// </summary> /// <param name="methodCall"> /// <see cref="MethodCall"/> to get expectation for /// </param> /// <returns>next <see cref="IMethodCallExpectation"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from /// a list. Not a big deal since we don't ever recover from any /// exceptions. /// </remarks> protected override IMethodCallExpectation nextExpectation(MethodCall methodCall) { if (expectations.Count == 0) { Assertion.Fail(String.Format( "Unexpected call {0}", methodCall )); } IMethodCallExpectation e = (IMethodCallExpectation)expectations[0]; expectations.RemoveAt(0); return e; }
/// <summary> /// Check actual incoming method call and return expected outgoing response. /// <see cref="IMethodCallExpectation.CheckCallAndSendResponse"/> /// </summary> public object CheckCallAndSendResponse( MethodCall call ) { _actualMethodCall = call; this.Verify( ); return _expectedReturnValue; }
/// <summary> /// Retrieve next expectation and remove from FIFO. /// </summary> /// <param name="methodCall"> /// <see cref="MethodCall"/> to get expectation for /// </param> /// <returns>next <see cref="IMethodCallExpectation"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from /// a list. Not a big deal since we don't ever recover from any /// exceptions. /// </remarks> protected virtual IMethodCallExpectation nextExpectation(MethodCall methodCall) { string methodName = methodCall.MethodName; IList list = (IList) expectations[methodName]; if (list == null) { if ( strict ) { throw new VerifyException(methodName + "() called too many times"); } return null; } if (list.Count == 0) { Assertion.Fail(methodName + "() called too many times"); } IMethodCallExpectation e = (IMethodCallExpectation) list[0]; list.RemoveAt(0); return e; }
/// <summary> /// Uses the given method to verify expectations for the method. /// </summary> /// <param name="mi">mathod called</param> /// <param name="args">arguments to the method</param> /// <returns>Return value, if any, from method call.</returns> public virtual object Call(MethodInfo mi, params object[] args) { MethodCall methodCall = new MethodCall(mi, args); string methodName = methodCall.MethodName; if (values.Contains(methodName)) { return values[methodName]; } IMethodCallExpectation e = nextExpectation(methodCall); return e.CheckCallAndSendResponse(methodCall); }