From: Griffin C. <gc...@us...> - 2005-01-01 22:58:25
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs IDynamicMock.cs IPredicate.cs Added Files: AbstractArgumentMutator.cs Assign.cs IArgumentMutator.cs IMockedCallHandler.cs Log Message: - Merged branch RFE_1001778 into head --- NEW FILE: Assign.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// An argument expectation that assigns a new value to ref/out /// parameters. /// </summary> public class Assign : AbstractArgumentMutator { private object _newValue; /// <summary> /// Default constructor. /// </summary> /// <param name="newValue">Value to assgin when Mutate calls are performed.</param> public Assign(object newValue) { _newValue = newValue; } /// <summary> /// Exchanges the input parameter with the value originally associate with this instance. /// </summary> /// <param name="parameterValue">argument to change</param> public override void Mutate(ref object parameterValue) { parameterValue = _newValue; } } } --- NEW FILE: IArgumentMutator.cs --- #region License // need license #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// Interface for specifying an expected modification to an argument. /// </summary> /// <remarks> /// This interface is delegate-like but since we can't extend /// delegates, we need to go with this. /// </remarks> /// <author>Choy Rim</author> public interface IArgumentMutator { /// <summary> /// Mutate the argument value. /// </summary> /// <param name="argument">reference to argument that must be modified</param> void Mutate(ref object argument); } } Index: IDynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IDynamicMock.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IDynamicMock.cs 23 Aug 2004 02:36:01 -0000 1.4 --- IDynamicMock.cs 1 Jan 2005 22:58:07 -0000 1.5 *************** *** 8,12 **** /// </summary> /// <see cref="DynamicMock"/> ! public interface IDynamicMock : IMockObject { /// <summary> --- 8,12 ---- /// </summary> /// <see cref="DynamicMock"/> ! public interface IDynamicMock : IMockObject, IMockedCallHandler { /// <summary> *************** *** 49,57 **** /// </summary> void SetValue(string methodName, object returnVal); - - /// <summary> - /// Make a call to a mocked up method name to check it meets its expectations. - /// </summary> - object Call(string methodName, params object[] args); } } --- 49,52 ---- Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DynamicMock.cs 1 Jan 2005 21:13:47 -0000 1.12 --- DynamicMock.cs 1 Jan 2005 22:58:07 -0000 1.13 *************** *** 1,11 **** using System; using System.Collections; using DotNetMock.Dynamic.Generate; namespace DotNetMock.Dynamic { /// <summary> ! /// Basic Dynamic Mock object /// </summary> public class DynamicMock : IDynamicMock { --- 1,20 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Collections; + using System.Reflection; + using DotNetMock.Dynamic.Generate; + #endregion namespace DotNetMock.Dynamic { /// <summary> ! /// Control class for creating mock objects during runtime. /// </summary> + /// <author>Griffin Caprio</author> + /// <author>Choy Rim</author> public class DynamicMock : IDynamicMock { *************** *** 168,179 **** } /// <summary> ! /// Method embedded into the generated mock object. Calls the method with the expected arguments, ! /// and verfies the method call against the set of expected methods. /// </summary> ! /// <param name="methodName">Method name to call</param> ! /// <param name="args">input arguments</param> ! /// <returns>Return value from method call, if any.</returns> ! public virtual object Call( string methodName, params object[] args ) { if (values.Contains(methodName)) { --- 177,188 ---- } /// <summary> ! /// Uses the given method to verify expectations for the method. /// </summary> ! /// <param name="mi">mathod called</param> ! /// <param name="args">arguments to the method</param> ! /// <returns>Return value, if any, from method call.</returns> ! public virtual object Call(MethodInfo mi, params object[] args) { + string methodName = getMethodName(mi); if (values.Contains(methodName)) { *************** *** 214,217 **** --- 223,241 ---- list.Add(e); } + /// <summary> + /// Returns the method name for the input <see cref="MethodInfo"/>. Accounts for property get and set methods. + /// </summary> + /// <param name="mi">method to get name from</param> + /// <returns>methond name for input method.</returns> + protected static string getMethodName( MethodInfo mi ) + { + string methodName = mi.Name; + if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) + { + methodName = methodName.Substring(4); + } + return methodName; + } + private void generate() { Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ExpectationMethod.cs 1 Jan 2005 21:13:50 -0000 1.8 --- ExpectationMethod.cs 1 Jan 2005 22:58:07 -0000 1.9 *************** *** 155,158 **** --- 155,164 ---- } Assertion.Assert(predicate.Eval(actualArg)); + // then handle mutators if any + IArgumentMutator mutator = expectedArg as IArgumentMutator; + if ( mutator!=null ) + { + mutator.Mutate(ref _methodArguments[i]); + } } Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DynamicOrderedMock.cs 1 Jan 2005 21:13:50 -0000 1.4 --- DynamicOrderedMock.cs 1 Jan 2005 22:58:07 -0000 1.5 *************** *** 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 System.Collections; + #endregion namespace DotNetMock.Dynamic *************** *** 37,47 **** } /// <summary> ! /// Calls the method on the mock object. /// </summary> ! /// <param name="methodName">Method name to call</param> ! /// <param name="args">Arguments to pass to the method</param> ! /// <returns>Return value, if any.</returns> ! public override object Call(string methodName, params object[] args) { if (values.Contains(methodName)) { --- 44,55 ---- } /// <summary> ! /// Uses the given method to verify expectations for the method. Also verifies method call order. /// </summary> ! /// <param name="mi">mathod called</param> ! /// <param name="args">arguments to the method</param> ! /// <returns>Return value, if any, from method call.</returns> ! public override object Call(MethodInfo mi, params object[] args) { + string methodName = getMethodName(mi); if (values.Contains(methodName)) { Index: IPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IPredicate.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IPredicate.cs 23 Aug 2004 02:36:01 -0000 1.5 --- IPredicate.cs 1 Jan 2005 22:58:07 -0000 1.6 *************** *** 10,16 **** /// A boolean result /// </summary> ! /// <param name="currentValue"></param> ! /// <returns></returns> ! bool Eval(object currentValue); } } --- 10,16 ---- /// A boolean result /// </summary> ! /// <param name="inputValue">Value to evaluate against</param> ! /// <returns>True/False if the current value equals the input value </returns> ! bool Eval(object inputValue); } } --- NEW FILE: IMockedCallHandler.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System.Reflection; #endregion namespace DotNetMock.Dynamic { /// <summary> /// Interface for handling mocked calls. /// </summary> /// <author>Choy Rim</author> public interface IMockedCallHandler { /// <summary> /// Mocked object calls this on any method call so that we can /// verify that the calls meet the expectations. /// </summary> object Call(MethodInfo mi, params object[] args); } } --- NEW FILE: AbstractArgumentMutator.cs --- #region License // need license #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// Abstract base class for all argument mutators. /// </summary> /// <author>Griffin Caprio</author> /// <author>Choy Rim</author> public abstract class AbstractArgumentMutator : IArgumentMutator, IPredicate { private IPredicate _predicate = null; /// <summary> /// Abstract method representing the exchanging of parameters /// </summary> /// <param name="argument">argument to change</param> public abstract void Mutate(ref object argument); /// <summary> /// Chains the current instance to another predicate to evaluate when exchanging parameters /// </summary> /// <param name="predicate"><see cref="IPredicate"/> to use for evaluation</param> /// <returns>reference to this instance</returns> public object AndRequire(IPredicate predicate) { _predicate = predicate; return this; } /// <summary> /// If there is no predicate associate with this mutator, returns true. Otherwise, evaluates the /// input value according to the predicate. /// </summary> /// <param name="inputValue">Value to evaluate</param> /// <returns>The Result of the predicate evaluation, or true if no predicate is assigned to this instance.</returns> public virtual bool Eval(object inputValue) { if ( _predicate==null ) { return true; } return _predicate.Eval(inputValue); } } } |