From: Choy R. <ch...@us...> - 2005-04-08 02:57:18
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7216/DotNetMock/Dynamic Modified Files: DynamicMock.cs ExpectationMethod.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: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** DynamicMock.cs 8 Apr 2005 00:05:09 -0000 1.21 --- DynamicMock.cs 8 Apr 2005 02:57:09 -0000 1.22 *************** *** 137,141 **** public virtual void Expect(string methodName, params object[] args) { ! ExpectAndReturn(methodName, null, args); } /// <summary> --- 137,149 ---- public virtual void Expect(string methodName, params object[] args) { ! if ( args.Length>0 ) ! { ! ExpectAndReturn(methodName, null, args); ! } ! else ! { ! // no argument checking ! addExpectation(new ExpectationMethod(methodName)); ! } } /// <summary> Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ExpectationMethod.cs 8 Apr 2005 00:05:09 -0000 1.22 --- ExpectationMethod.cs 8 Apr 2005 02:57:09 -0000 1.23 *************** *** 41,45 **** /// </summary> /// <param name="methodName">Method name to expect</param> ! public ExpectationMethod( string methodName ) : this( methodName, null ) {} /// <summary> /// Default Constructor --- 41,48 ---- /// </summary> /// <param name="methodName">Method name to expect</param> ! public ExpectationMethod( string methodName ) ! : this(methodName, null, null, null) ! { ! } /// <summary> /// Default Constructor *************** *** 47,51 **** /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! public ExpectationMethod( string methodName, object returnValue ) : this( methodName, returnValue, null ){} /// <summary> /// Default Constructor --- 50,57 ---- /// <param name="methodName">Method name to expect</param> /// <param name="returnValue">return value when expectation is called</param> ! public ExpectationMethod( string methodName, object returnValue ) ! : this( methodName, returnValue, null, null ) ! { ! } /// <summary> /// Default Constructor *************** *** 54,58 **** /// <param name="returnValue">return value when expectation is called</param> /// <param name="argumentExpectations">Expectations on the arguments</param> ! public ExpectationMethod( string methodName, object returnValue, object[] argumentExpectations ) : this( methodName, returnValue, argumentExpectations, null ){} /// <summary> /// Default Constructor --- 60,71 ---- /// <param name="returnValue">return value when expectation is called</param> /// <param name="argumentExpectations">Expectations on the arguments</param> ! public ExpectationMethod( ! string methodName, ! object returnValue, ! object[] argumentExpectations ! ) ! : this( methodName, returnValue, argumentExpectations, null ) ! { ! } /// <summary> /// Default Constructor *************** *** 62,76 **** /// <param name="argumentExpectations">Expectations on the arguments</param> /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( string methodName, object returnValue, object[] argumentExpectations, Exception expectedException) { _expectedMethodName = methodName; ! if (argumentExpectations == null) ! { ! _argumentExpectations = new object[0]; ! } ! else ! { ! _argumentExpectations = argumentExpectations; ! } _expectedReturnValue = returnValue; --- 75,87 ---- /// <param name="argumentExpectations">Expectations on the arguments</param> /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( ! string methodName, ! object returnValue, ! object[] argumentExpectations, ! Exception expectedException ! ) { _expectedMethodName = methodName; ! _argumentExpectations = argumentExpectations; _expectedReturnValue = returnValue; *************** *** 197,203 **** )); } object[] actualArguments = ActualMethodCall.Arguments; ! // actual arguments must be greater than or equal to expectations ! if ( actualArguments.Length<_argumentExpectations.Length) { Assertion.Fail(String.Format( --- 208,218 ---- )); } + if ( _argumentExpectations==null ) + { + return; + } object[] actualArguments = ActualMethodCall.Arguments; ! // actual arguments must be equal to expectations ! if ( actualArguments.Length!=_argumentExpectations.Length) { Assertion.Fail(String.Format( |