From: Choy R. <ch...@us...> - 2005-02-17 05:29:46
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3352/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Log Message: Record MethodInfo of actual method call instead of just method name. This will allow us to have even better assertion failure messages. And probably other benefits I can't think of right now. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** DynamicOrderedMock.cs 17 Feb 2005 04:44:17 -0000 1.6 --- DynamicOrderedMock.cs 17 Feb 2005 05:29:38 -0000 1.7 *************** *** 62,66 **** ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.SetActualMethodCall(methodName, args); e.Verify(); return e.ReturnValue; --- 62,66 ---- ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); ! e.SetActualMethodCall(mi, args); e.Verify(); return e.ReturnValue; Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DynamicMock.cs 17 Feb 2005 04:44:17 -0000 1.14 --- DynamicMock.cs 17 Feb 2005 05:29:38 -0000 1.15 *************** *** 205,209 **** ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.SetActualMethodCall(methodName, args); e.Verify(); return e.ReturnValue; --- 205,209 ---- ExpectationMethod e = (ExpectationMethod)list[0]; list.RemoveAt(0); ! e.SetActualMethodCall(mi, args); e.Verify(); return e.ReturnValue; Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ExpectationMethod.cs 17 Feb 2005 04:44:17 -0000 1.13 --- ExpectationMethod.cs 17 Feb 2005 05:29:38 -0000 1.14 *************** *** 1,4 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; + using System.Reflection; + using DotNetMock.Dynamic.Predicates; + #endregion namespace DotNetMock.Dynamic *************** *** 14,21 **** private string _expectedMethodName; /// <summary> - /// Method Name of the called method - /// </summary> - private string _methodName; - /// <summary> /// Any expected arguments for the expected method call /// </summary> --- 21,24 ---- *************** *** 34,37 **** --- 37,44 ---- private Exception _expectedException; /// <summary> + /// <see cref="MethodInfo"/> of actual method call. + /// </summary> + private MethodInfo _actualMethod = null; + /// <summary> /// Default Constructor /// </summary> *************** *** 88,99 **** } /// <summary> ! /// Sets this expectations actual method name and method arguments /// </summary> ! /// <param name="methodName">Method Name</param> ! /// <param name="methodArguments">Arguments</param> ! public void SetActualMethodCall( string methodName, params object[] methodArguments ) { ! _methodName = methodName; ! _methodArguments = methodArguments; } //TODO: Refactor methods --- 95,145 ---- } /// <summary> ! /// True if actual method call was set. ! /// <seealso cref="SetActualMethodCall"/> /// </summary> ! public bool ActualMethodCallWasSet { ! get { return _actualMethod!=null; } ! } ! /// <summary> ! /// <see cref="MethodInfo"/> of actual method called. ! /// </summary> ! public MethodInfo ActualMethod ! { ! get ! { ! if ( ! ActualMethodCallWasSet ) ! { ! throw new InvalidOperationException( ! "Cannot access ActualMethod property "+ ! "before SetActualMethodCall" ! ); ! } ! return _actualMethod; ! } ! } ! /// <summary> ! /// Name of actual method called. ! /// </summary> ! public string ActualMethodName ! { ! get { ! string name = ActualMethod.Name; ! if ( name.StartsWith("get_") || name.StartsWith("set_") ) ! { ! name = name.Substring(4); ! } ! return name; ! } ! } ! /// <summary> ! /// Set actual method call <see cref="MethodInfo"/> and arguments. ! /// </summary> ! /// <param name="actualMethod">actual method</param> ! /// <param name="actualArguments">actual arguments</param> ! public void SetActualMethodCall( MethodInfo actualMethod, params object[] actualArguments ) ! { ! _actualMethod = actualMethod; ! _methodArguments = actualArguments; } //TODO: Refactor methods *************** *** 128,134 **** public override void Verify() { ! if( ExpectedMethodName != _methodName ) { ! Assertion.Fail( ExpectedMethodName + "(" + argsToString(_expectedMethodArguments) + ") expected, but " + _methodName + "(" + argsToString(_methodArguments) + ") called" ); } --- 174,192 ---- public override void Verify() { ! if ( ! ActualMethodCallWasSet ) { ! Assertion.Fail(String.Format( ! "{0}({1}) expected but never called.", ! ExpectedMethodName, ! argsToString(_expectedMethodArguments) ! )); ! } ! if( ExpectedMethodName != ActualMethodName ) ! { ! Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2}({3}) called.", ! ExpectedMethodName, argsToString(_expectedMethodArguments), ! ActualMethodName, argsToString(_methodArguments) ! )); } |