/// <summary> /// Adds a <see cref="IMethodCallExpectation"/> to the list of expectations of the mock object. /// </summary> /// <param name="e">Expectation to add</param> protected virtual void addExpectation(IMethodCallExpectation e) { IList list = (IList)expectations[e.ExpectedMethodName]; if (list == null) { list = new ArrayList(); expectations[e.ExpectedMethodName] = list; } list.Add(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)); }
/// <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> /// Adds a <see cref="IMethodCallExpectation"/> to the list of expectations of the mock object. /// </summary> /// <param name="e">Expectation to add</param> protected override void addExpectation(IMethodCallExpectation e) { // prevent adding a Call expectation after a NoCall expectation if (e.ExpectationType == ExpectationMethodType.Call) { foreach (ExpectationMethod em in expectations) { if (em.ExpectationType == ExpectationMethodType.NoCall) { Assertion.Fail("ExpectNoCall must be last on a DynamicOrderedMock"); } } } expectations.Add(e); }
/// <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> /// Adds a <see cref="IMethodCallExpectation"/> to the list of expectations of the mock object. /// </summary> /// <param name="e">Expectation to add</param> protected virtual void addExpectation(IMethodCallExpectation e) { IList list = (IList) expectations[e.ExpectedMethodName]; if (list == null) { list = new ArrayList(); expectations[e.ExpectedMethodName] = list; } list.Add(e); }