/// <summary> /// Implements IMocker. /// </summary> public void HandleCall(MockingProxy proxy, MockableCall call) { try { IExpectedCall expectedCall = DequeueExpectedCall(); expectedCall.Replay(call); } catch (ArgumentOutOfRangeException) { throw new ReplayMockException(call, "Call not expected."); } }
/// <summary> /// Replays the expected call and checks its arguments. /// </summary> public void Replay(MockableCall call) { // Check argument count: if (arguments.Length != call.Method.GetParameters().Length) { throw new ReplayMockException(call, "Call to method \"" + call.Method.Name + "\" expected wrong number of arguments."); } // Check arguments individually: int i = -1; foreach (System.Reflection.ParameterInfo pinfo in call.GetInParameters()) { i++; if (pinfo.IsOut) { continue; // Skip output parameters } if ((arguments[pinfo.Position] == null) && (call.InArgs[i] == null)) { continue; // OK if both NULL } if ((arguments[pinfo.Position] == null) || (call.InArgs[i] == null)) { throw new ReplayMockException(call, "Argument \"" + pinfo.Name + "\" of method \"" + call.MethodSignature + "\" has a different value than expected."); } if (arguments[pinfo.Position] is IExpectedValue) { if ((arguments[pinfo.Position] as IExpectedValue).MatchesExpectation(call.InArgs[i])) { continue; } else { throw new ReplayMockException(call, "Argument \"" + pinfo.Name + "\" of method \"" + call.MethodSignature + "\" has a different value than expected."); } } if (!arguments[pinfo.Position].Equals(call.InArgs[i])) { throw new ReplayMockException(call, "Argument \"" + pinfo.Name + "\" of method \"" + call.MethodSignature + "\" has a different value than expected."); } } // If all passed, replay the call: innerCall.Replay(call); }