From: Griffin C. <gc...@us...> - 2005-01-01 21:14:33
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30794/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Log Message: - Added remaining XML docs to DotNetMock project - Removed 'using' directives - Minor coding stds refactorings - Removed Apache license from Predicate classes. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DynamicOrderedMock.cs 9 Oct 2004 21:14:12 -0000 1.3 --- DynamicOrderedMock.cs 1 Jan 2005 21:13:50 -0000 1.4 *************** *** 4,17 **** namespace DotNetMock.Dynamic { public class DynamicOrderedMock : DynamicMock { private IList expectations = new ArrayList(); ! public DynamicOrderedMock( string name ) : base( name ) ! { ! } public DynamicOrderedMock( Type type, string name ) : base( type, name ){} public DynamicOrderedMock( Type type ) : base( type ) {} ! public override void Verify() { --- 4,33 ---- namespace DotNetMock.Dynamic { + /// <summary> + /// Represents a dynamic mock object that enables expectations to be set to be called in a certain order. + /// </summary> public class DynamicOrderedMock : DynamicMock { private IList expectations = new ArrayList(); ! /// <summary> ! /// Default constructor ! /// </summary> ! /// <param name="name">Name for the mock object</param> ! public DynamicOrderedMock( string name ) : base( name ) {} ! /// <summary> ! /// Default Constructor ! /// </summary> ! /// <param name="type">Type to generate the mock for</param> ! /// <param name="name">Name for the mock object</param> public DynamicOrderedMock( Type type, string name ) : base( type, name ){} + /// <summary> + /// Default Constructor + /// </summary> + /// <param name="type">Type to generate the mock for</param> public DynamicOrderedMock( Type type ) : base( type ) {} ! /// <summary> ! /// Verifies the mock object. ! /// </summary> public override void Verify() { *************** *** 20,23 **** --- 36,45 ---- } } + /// <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) { *************** *** 48,52 **** return String.Empty; } ! protected override void addExpectation(ExpectationMethod e) { --- 70,77 ---- return String.Empty; } ! /// <summary> ! /// Adds a <see cref="ExpectationMethod"/> to the list of expectations of the mock object. ! /// </summary> ! /// <param name="e">Expectation to add</param> protected override void addExpectation(ExpectationMethod e) { Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DynamicMock.cs 12 Nov 2004 16:03:29 -0000 1.11 --- DynamicMock.cs 1 Jan 2005 21:13:47 -0000 1.12 *************** *** 5,8 **** --- 5,11 ---- namespace DotNetMock.Dynamic { + /// <summary> + /// Basic Dynamic Mock object + /// </summary> public class DynamicMock : IDynamicMock { *************** *** 11,18 **** private bool strict; private IDictionary expectations; - protected IDictionary values; private bool verified; private Type type; ! public DynamicMock() { --- 14,26 ---- private bool strict; private IDictionary expectations; private bool verified; private Type type; ! /// <summary> ! /// Holds the expectation values for an specified methods. ! /// </summary> ! protected IDictionary values; ! /// <summary> ! /// Default Constructor ! /// </summary> public DynamicMock() { *************** *** 21,28 **** --- 29,44 ---- values = new Hashtable(); } + /// <summary> + /// Default Constructor + /// </summary> + /// <param name="name">Name to assign to the generated mock</param> public DynamicMock(string name) : this() { _name = name; } + /// <summary> + /// Default Constructor + /// </summary> + /// <param name="type">Type to generate the mock for.</param> public DynamicMock( Type type ) : this() { *************** *** 36,44 **** this.type = type; } ! public DynamicMock( Type type, string name ) : this( name ) { this.type = type; } public virtual object Object { --- 52,67 ---- this.type = type; } ! /// <summary> ! /// Default Constructor ! /// </summary> ! /// <param name="type">Type to generate the mock for.</param> ! /// <param name="name">Name for the generated mock</param> public DynamicMock( Type type, string name ) : this( name ) { this.type = type; } + /// <summary> + /// Returns the generated mock object for the given type. + /// </summary> public virtual object Object { *************** *** 52,61 **** } } ! ! private void generate() ! { ! ClassGenerator cg = new ClassGenerator(); ! obj = cg.Generate(type, this); ! } public virtual bool Strict { --- 75,82 ---- } } ! /// <summary> ! /// Sets / Gets the Strict flag for the mock object. If this flag is set, only specific operations ! /// will be allowed on the generated mock object. ! /// </summary> public virtual bool Strict { *************** *** 63,66 **** --- 84,90 ---- set { strict = value; } } + /// <summary> + /// Gets / Sets the name for the generated mock object + /// </summary> public string MockName { *************** *** 75,79 **** get { return verified; } } - /// <summary> /// Throws NotImplementedException. --- 99,102 ---- *************** *** 84,87 **** --- 107,113 ---- throw new NotImplementedException(methodName + " not currently implemented"); } + /// <summary> + /// Verifies the this mock object. + /// </summary> public virtual void Verify() { *************** *** 95,124 **** } } ! public virtual void Expect(string methodName, params object[] args) { ExpectAndReturn(methodName, null, args); } ! public virtual void ExpectNoCall(string methodName) { addExpectation(new ExpectationMethod(methodName, null, null, new VerifyException(methodName + "() should never be called."))); } ! public virtual void ExpectAndReturn( string methodName, object result, params object[] args ) { addExpectation( new ExpectationMethod( methodName, result, args ) ); } ! public virtual void ExpectAndThrow( string methodName, Exception e, params object[] args) { addExpectation( new ExpectationMethod( methodName, null, args, e ) ); } ! public virtual void SetValue(string methodName, object returnVal) { values[methodName] = returnVal; } ! public virtual object Call( string methodName, params object[] args ) { --- 121,177 ---- } } ! /// <summary> ! /// Adds expected call to the method with the supplied arguments. ! /// </summary> ! /// <param name="methodName">Name of expected method to be called</param> ! /// <param name="args">Expected arguments</param> public virtual void Expect(string methodName, params object[] args) { ExpectAndReturn(methodName, null, args); } ! /// <summary> ! /// Adds the expectation that the supplied method should not be called. ! /// </summary> ! /// <param name="methodName">Name of the method</param> public virtual void ExpectNoCall(string methodName) { addExpectation(new ExpectationMethod(methodName, null, null, new VerifyException(methodName + "() should never be called."))); } ! /// <summary> ! /// Addes a expected call with the supplied parameters, that returns an expected result. ! /// </summary> ! /// <param name="methodName">Name of expected method to be called</param> ! /// <param name="result">Results to return</param> ! /// <param name="args">Expected arguments</param> public virtual void ExpectAndReturn( string methodName, object result, params object[] args ) { addExpectation( new ExpectationMethod( methodName, result, args ) ); } ! /// <summary> ! /// Addes an expected call that results in the given exception being thrown. ! /// </summary> ! /// <param name="methodName">Method to call</param> ! /// <param name="e">Exception to throw</param> ! /// <param name="args">Expected arguments</param> public virtual void ExpectAndThrow( string methodName, Exception e, params object[] args) { addExpectation( new ExpectationMethod( methodName, null, args, e ) ); } ! /// <summary> ! /// Sets the return value for the supplied method ! /// </summary> ! /// <param name="methodName">Method to call</param> ! /// <param name="returnVal">Value to return</param> public virtual void SetValue(string methodName, object returnVal) { values[methodName] = returnVal; } ! /// <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 ) { *************** *** 147,151 **** return e.ReturnValue; } ! protected virtual void addExpectation(ExpectationMethod e) { --- 200,207 ---- return e.ReturnValue; } ! /// <summary> ! /// Adds a <see cref="ExpectationMethod"/> to the list of expectations of the mock object. ! /// </summary> ! /// <param name="e">Expectation to add</param> protected virtual void addExpectation(ExpectationMethod e) { *************** *** 158,161 **** --- 214,222 ---- list.Add(e); } + private void generate() + { + ClassGenerator cg = new ClassGenerator(); + obj = cg.Generate(type, this); + } } } Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ExpectationMethod.cs 9 Oct 2004 21:14:12 -0000 1.7 --- ExpectationMethod.cs 1 Jan 2005 21:13:50 -0000 1.8 *************** *** 36,42 **** --- 36,61 ---- /// Default Constructor /// </summary> + /// <param name="methodName">Method name to expect</param> public ExpectationMethod( string methodName ) : this( methodName, null ) {} + /// <summary> + /// Default Constructor + /// </summary> + /// <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 + /// </summary> + /// <param name="methodName">Method name to expect</param> + /// <param name="returnValue">return value when expectation is called</param> + /// <param name="expectedArguments">Arguments to expect when called.</param> public ExpectationMethod( string methodName, object returnValue, object[] expectedArguments ) : this( methodName, returnValue, expectedArguments, null ){} + /// <summary> + /// Default Constructor + /// </summary> + /// <param name="methodName">Method name to expect</param> + /// <param name="returnValue">return value when expectation is called</param> + /// <param name="expectedArguments">Arguments to expect when called.</param> + /// <param name="expectedException">Exception to throw when called.</param> public ExpectationMethod( string methodName, object returnValue, object[] expectedArguments, Exception expectedException) { *************** *** 69,73 **** } /// <summary> ! /// Sets this expectations actual method name & method arguments /// </summary> /// <param name="methodName">Method Name</param> --- 88,92 ---- } /// <summary> ! /// Sets this expectations actual method name and method arguments /// </summary> /// <param name="methodName">Method Name</param> *************** *** 78,81 **** --- 97,104 ---- _methodArguments = methodArguments; } + /// <summary> + /// Calls the input method on this expectation + /// </summary> + /// <param name="methodName">Method name to call</param> public void Call( string methodName ) { |