public void GetParametersTest() { // Create call: MockingProxy callee = new MockingProxy(typeof(Sample.FooBar), null, "m1"); MockableCall call = new MockableCall(callee, typeof(Sample.FooBar).GetMethod("SomeMethodWithInsAndOuts"), new object[] { 1, 2, null, 3 }); // Check parameters: Assert.AreEqual(3, call.GetInParameters().Length, "Input parameters count mismatch."); Assert.AreEqual(2, call.GetOutParameters().Length, "Output parameters count mismatch."); }
public void IsInOutParameterTest() { // Create call: MockingProxy callee = new MockingProxy(typeof(Sample.FooBar), null, "m1"); MockableCall call = new MockableCall(callee, typeof(Sample.FooBar).GetMethod("SomeMethodWithInsAndOuts"), new object[] { 1, 2, null, 3 }); // Check in parameters: foreach (global::System.Reflection.ParameterInfo param in call.GetInParameters()) { Assert.IsTrue(call.IsParameterIn(param.Position)); } // Check out parameters: foreach (global::System.Reflection.ParameterInfo param in call.GetOutParameters()) { Assert.IsTrue(call.IsParameterOut(param.Position)); } // All params must be IN, OUT or IN/OUT: foreach (global::System.Reflection.ParameterInfo param in call.Method.GetParameters()) { Assert.IsTrue(call.IsParameterIn(param.Position) || call.IsParameterOut(param.Position)); } }
/// <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); }