From: Choy R. <ch...@us...> - 2005-04-08 02:57:18
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7216/DotNetMock.Tests/Dynamic Modified Files: AbstractDynamicMockTests.cs ExpectationMethodTests.cs Log Message: BUG 1163942 : expectation should fail if passed the wrong number of arguments. But there is some legacy functionality we need to support so I needed to do some hacking to ensure that we can still specify that we DON'T want to check arguments. perhaps this is better handled through an expectation hierarchy as Roman suggested. Index: ExpectationMethodTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/ExpectationMethodTests.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ExpectationMethodTests.cs 8 Apr 2005 00:05:08 -0000 1.14 --- ExpectationMethodTests.cs 8 Apr 2005 02:57:09 -0000 1.15 *************** *** 24,27 **** --- 24,29 ---- void Method2(int x, int y, int z); void Method3(); + void Method4(int x); + void Method4(int x, int y); } *************** *** 29,37 **** static readonly MethodInfo method2 = typeof(IMethods).GetMethod("Method2"); static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); ! [TearDown] ! public void Destroy() { ! methodCallExpectation = null; } [Test] --- 31,72 ---- static readonly MethodInfo method2 = typeof(IMethods).GetMethod("Method2"); static readonly MethodInfo method3 = typeof(IMethods).GetMethod("Method3"); + static readonly MethodInfo method4x = typeof(IMethods).GetMethod( + "Method4", + new Type[] { typeof(int) } + ); + static readonly MethodInfo method4xy = typeof(IMethods).GetMethod( + "Method4", + new Type[] { typeof(int), typeof(int) } + ); ! [ExpectedException( ! typeof(AssertionException), ! "Expected 2 arguments but received 1 in method call Method4(x=1)." ! )] ! [Test] public void CallMethodWithSameNameButFewerArguments() { ! methodCallExpectation = new ExpectationMethod( ! method4xy.Name, ! null, ! new object[] { 1, 2 } ! ); ! MethodCall call = new MethodCall(method4x, 1); ! object returnValue = methodCallExpectation.CheckCallAndSendResponse(call); ! methodCallExpectation.Verify(); ! } ! [ExpectedException( ! typeof(AssertionException), ! "Expected 1 arguments but received 2 in method call Method4(x=1, y=2)." ! )] ! [Test] public void CallMethodWithSameNameButMoreArguments() ! { ! methodCallExpectation = new ExpectationMethod( ! method4x.Name, ! null, ! new object[] { 1 } ! ); ! MethodCall call = new MethodCall(method4xy, 1, 2); ! object returnValue = methodCallExpectation.CheckCallAndSendResponse(call); ! methodCallExpectation.Verify(); } [Test] Index: AbstractDynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/AbstractDynamicMockTests.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractDynamicMockTests.cs 18 Feb 2005 02:16:08 -0000 1.3 --- AbstractDynamicMockTests.cs 8 Apr 2005 02:57:09 -0000 1.4 *************** *** 25,28 **** --- 25,38 ---- protected MethodInfo method1; + protected static readonly MethodInfo METHOD2A = typeof(IBlah).GetMethod( + "Method2", + new Type[] { typeof(int) } + ); + protected static readonly MethodInfo METHOD2AB = typeof(IBlah).GetMethod( + "Method2", + new Type[] { typeof(int), typeof(int) } + ); + + /// <summary> /// Create instance of <see cref="IDynamicMock"/> to test. *************** *** 47,50 **** --- 57,63 ---- void Method0(object p0, object p1); object Method1(object p0); + + void Method2(int a); + void Method2(int a, int b); } *************** *** 61,64 **** --- 74,87 ---- } + [ExpectedException(typeof(AssertionException))] + [Test] public void FailsIfPassedTooManyArguments() + { + mock = new DynamicMock(typeof(IBlah)); + mock.Expect("Method2", 1); + + IBlah blah = (IBlah) mock.Object; + blah.Method2(1, 2); + } + [Test] public void SetsRefParameter() |