From: Choy R. <ch...@us...> - 2005-02-19 08:39:29
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22599/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs Log Message: Incorporated MethodCall into ExpectationMethod Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ExpectationMethod.cs 18 Feb 2005 02:16:08 -0000 1.16 --- ExpectationMethod.cs 19 Feb 2005 08:39:20 -0000 1.17 *************** *** 25,32 **** private object[] _expectedMethodArguments; /// <summary> - /// Arguments to the method that was called - /// </summary> - private object[] _actualMethodArguments; - /// <summary> /// Expected return value for this method call if any. /// </summary> --- 25,28 ---- *************** *** 37,43 **** private Exception _expectedException; /// <summary> ! /// <see cref="MethodInfo"/> of actual method call. /// </summary> ! private MethodInfo _actualMethod = null; /// <summary> /// Default Constructor --- 33,39 ---- private Exception _expectedException; /// <summary> ! /// Actual <see cref="MethodCall"/>. /// </summary> ! private MethodCall _actualMethodCall = null; /// <summary> /// Default Constructor *************** *** 100,104 **** public bool ActualMethodCallWasSet { ! get { return _actualMethod!=null; } } /// <summary> --- 96,100 ---- public bool ActualMethodCallWasSet { ! get { return _actualMethodCall!=null; } } /// <summary> *************** *** 109,120 **** get { ! if ( ! ActualMethodCallWasSet ) ! { ! throw new InvalidOperationException( ! "Cannot access ActualMethod property "+ ! "before SetActualMethodCall" ! ); ! } ! return _actualMethod; } } --- 105,109 ---- get { ! return ActualMethodCall.Method; } } *************** *** 134,137 **** --- 123,160 ---- } /// <summary> + /// Actual method call. + /// </summary> + public MethodCall ActualMethodCall + { + get + { + if ( ! ActualMethodCallWasSet ) + { + throw new InvalidOperationException( + "Cannot get property ActualMethodCall "+ + "before setting it." + ); + } + return _actualMethodCall; + } + set + { + if ( value==null ) + { + throw new ArgumentNullException( + "Cannot set ActualMethodCall property to null" + ); + } + if ( ActualMethodCallWasSet ) + { + throw new InvalidOperationException( + "Cannot set property ActualMethodCall "+ + "more than once." + ); + } + _actualMethodCall = value; + } + } + /// <summary> /// Set actual method call <see cref="MethodInfo"/> and arguments. /// </summary> *************** *** 140,145 **** public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) { ! _actualMethod = actualMethod; ! _actualMethodArguments = actualArguments; } //TODO: Refactor methods --- 163,167 ---- public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) { ! ActualMethodCall = new MethodCall(actualMethod, actualArguments); } //TODO: Refactor methods *************** *** 185,218 **** { Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2}({3}) called.", ExpectedMethodName, argsToString(_expectedMethodArguments), ! ActualMethodName, argsToString(_actualMethodArguments) ! )); ! } ! // check if the actual argument count is correct ! // TODO: ideally this would be done in the constructor if possible ! ParameterInfo[] pis = ActualMethod.GetParameters(); ! if ( pis.Length!=_actualMethodArguments.Length ) ! { ! throw new InvalidOperationException(String.Format( ! "Method {0} takes {1} arguments but received {2}.", ! ActualMethodName, ! pis.Length, ! _actualMethodArguments.Length )); } ! /* cannot check that actual args size matches expected ! * because we want to be able to expect using just method name ! if ( _actualMethodArguments.Length!=_expectedMethodArguments.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ ! "in method call {2}({3}).", _expectedMethodArguments.Length, ! _actualMethodArguments.Length, ! ActualMethodName, argsToString(_actualMethodArguments) )); } - */ // assert that each passed in arg is validated by the appropriate predicate. --- 207,227 ---- { Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2} called.", ExpectedMethodName, argsToString(_expectedMethodArguments), ! ActualMethodCall )); } ! object[] actualArguments = ActualMethodCall.Arguments; ! // actual arguments must be greater than or equal to expectations ! if ( actualArguments.Length<_expectedMethodArguments.Length) { Assertion.Fail(String.Format( "Expected {0} arguments but received {1} "+ ! "in method call {2}.", _expectedMethodArguments.Length, ! actualArguments.Length, ! ActualMethodCall )); } // assert that each passed in arg is validated by the appropriate predicate. *************** *** 220,224 **** { object argumentExpectation = _expectedMethodArguments[i]; ! object actualArgument = _actualMethodArguments[i]; // evaluate whether input expectations have been met --- 229,233 ---- { object argumentExpectation = _expectedMethodArguments[i]; ! object actualArgument = actualArguments[i]; // evaluate whether input expectations have been met *************** *** 229,241 **** if ( ! isPredicateSatisfied ) { - ParameterInfo pi = pis[i]; Assertion.Fail(String.Format( ! "Failed to satisfy '{0}' on argument {2} ({1}) "+ ! "of method call {3}({4})", predicate, - pi.Name, i, ! ExpectedMethodName, ! argsToString(_actualMethodArguments) )); } --- 238,247 ---- if ( ! isPredicateSatisfied ) { Assertion.Fail(String.Format( ! "Failed to satisfy '{0}' on argument[{1}] "+ ! "of method call {2}", predicate, i, ! ActualMethodCall )); } *************** *** 245,249 **** if ( mutator!=null ) { ! mutator.Mutate(ref _actualMethodArguments[i]); } } --- 251,255 ---- if ( mutator!=null ) { ! mutator.Mutate(ref actualArguments[i]); } } |