From: Griffin C. <gc...@us...> - 2005-01-01 22:32:18
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13904/DotNetMock/Dynamic Modified Files: Tag: RFE_1001778 DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Log Message: - Merged changes from HEAD Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -C2 -d -r1.3.2.3 -r1.3.2.4 *** DynamicOrderedMock.cs 1 Jan 2005 21:57:15 -0000 1.3.2.3 --- DynamicOrderedMock.cs 1 Jan 2005 22:32:08 -0000 1.3.2.4 *************** *** 11,24 **** 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() { --- 11,40 ---- 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() { *************** *** 56,60 **** return String.Empty; } ! protected override void addExpectation(ExpectationMethod e) { --- 72,79 ---- 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.2.3 retrieving revision 1.11.2.4 diff -C2 -d -r1.11.2.3 -r1.11.2.4 *** DynamicMock.cs 1 Jan 2005 21:57:15 -0000 1.11.2.3 --- DynamicMock.cs 1 Jan 2005 22:32:08 -0000 1.11.2.4 *************** *** 23,30 **** private bool strict; private IDictionary expectations; - protected IDictionary values; private bool verified; private Type type; ! public DynamicMock() { --- 23,35 ---- 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() { *************** *** 33,40 **** --- 38,53 ---- 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() { *************** *** 48,56 **** this.type = type; } ! public DynamicMock( Type type, string name ) : this( name ) { this.type = type; } public virtual object Object { --- 61,76 ---- 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 { *************** *** 64,73 **** } } ! ! private void generate() ! { ! ClassGenerator cg = new ClassGenerator(); ! obj = cg.Generate(type, this); ! } public virtual bool Strict { --- 84,91 ---- } } ! /// <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 { *************** *** 75,78 **** --- 93,99 ---- set { strict = value; } } + /// <summary> + /// Gets / Sets the name for the generated mock object + /// </summary> public string MockName { *************** *** 87,91 **** get { return verified; } } - /// <summary> /// Throws NotImplementedException. --- 108,111 ---- *************** *** 96,99 **** --- 116,122 ---- throw new NotImplementedException(methodName + " not currently implemented"); } + /// <summary> + /// Verifies the this mock object. + /// </summary> public virtual void Verify() { *************** *** 107,131 **** } } ! 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) { --- 130,175 ---- } } ! /// <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) { *************** *** 159,165 **** return e.ReturnValue; } ! ! ! protected virtual void addExpectation(ExpectationMethod e) { --- 203,210 ---- 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) { *************** *** 182,185 **** --- 227,236 ---- return methodName; } + + 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.2.1 retrieving revision 1.7.2.2 diff -C2 -d -r1.7.2.1 -r1.7.2.2 *** ExpectationMethod.cs 30 Dec 2004 00:04:36 -0000 1.7.2.1 --- ExpectationMethod.cs 1 Jan 2005 22:32:08 -0000 1.7.2.2 *************** *** 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 ) { |