From: Choy R. <ch...@us...> - 2005-03-04 00:18:51
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4341/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs Added Files: IMethodCallExpectation.cs Log Message: Factor out minimal interface for method call expectations. --- NEW FILE: IMethodCallExpectation.cs --- #region License // Copyright (c) 2005 Choy Rim. All rights reserved. #endregion #region Imports using System; #endregion namespace DotNetMock.Dynamic { /// <summary> /// Interface for expectations on method calls.. /// </summary> public interface IMethodCallExpectation { /// <summary> /// Actual <see cref="MethodCall"/>. /// </summary> MethodCall ActualMethodCall { set; } /// <summary> /// Expected method name. /// </summary> string ExpectedMethodName { get; } /// <summary> /// Expected return value. /// </summary> object ReturnValue { get; } /// <summary> /// Verify this expectation. /// </summary> /// <remarks> /// I'd extend <see cref="IVerifiable"/> but that /// currently causes compilation problems. /// </remarks> void Verify(); } } Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DynamicOrderedMock.cs 19 Feb 2005 22:14:28 -0000 1.11 --- DynamicOrderedMock.cs 4 Mar 2005 00:18:42 -0000 1.12 *************** *** 40,51 **** { if( expectations.Count!=0 ) { ! Assertion.Fail( "Unfinished scenario: method " + ((ExpectationMethod)expectations[0]).ExpectedMethodName + "() wasn't called"); } } /// <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) { expectations.Add(e); --- 40,51 ---- { if( expectations.Count!=0 ) { ! Assertion.Fail( "Unfinished scenario: method " + ((IMethodCallExpectation)expectations[0]).ExpectedMethodName + "() wasn't called"); } } /// <summary> ! /// Adds a <see cref="IMethodCallExpectation"/> to the list of expectations of the mock object. /// </summary> /// <param name="e">Expectation to add</param> ! protected override void addExpectation(IMethodCallExpectation e) { expectations.Add(e); *************** *** 57,61 **** /// <see cref="MethodCall"/> to get expectation for /// </param> ! /// <returns>next <see cref="ExpectationMethod"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from --- 57,61 ---- /// <see cref="MethodCall"/> to get expectation for /// </param> ! /// <returns>next <see cref="IMethodCallExpectation"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from *************** *** 63,67 **** /// exceptions. /// </remarks> ! protected override ExpectationMethod nextExpectation(MethodCall methodCall) { if (expectations.Count == 0) --- 63,67 ---- /// exceptions. /// </remarks> ! protected override IMethodCallExpectation nextExpectation(MethodCall methodCall) { if (expectations.Count == 0) *************** *** 72,76 **** )); } ! ExpectationMethod e = (ExpectationMethod)expectations[0]; expectations.RemoveAt(0); return e; --- 72,76 ---- )); } ! IMethodCallExpectation e = (IMethodCallExpectation)expectations[0]; expectations.RemoveAt(0); return e; Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** DynamicMock.cs 19 Feb 2005 22:14:28 -0000 1.19 --- DynamicMock.cs 4 Mar 2005 00:18:41 -0000 1.20 *************** *** 190,194 **** return values[methodName]; } ! ExpectationMethod e = nextExpectation(methodCall); e.ActualMethodCall = methodCall; e.Verify(); --- 190,194 ---- return values[methodName]; } ! IMethodCallExpectation e = nextExpectation(methodCall); e.ActualMethodCall = methodCall; e.Verify(); *************** *** 196,203 **** } /// <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) { IList list = (IList) expectations[e.ExpectedMethodName]; --- 196,203 ---- } /// <summary> ! /// Adds a <see cref="IMethodCallExpectation"/> to the list of expectations of the mock object. /// </summary> /// <param name="e">Expectation to add</param> ! protected virtual void addExpectation(IMethodCallExpectation e) { IList list = (IList) expectations[e.ExpectedMethodName]; *************** *** 215,219 **** /// <see cref="MethodCall"/> to get expectation for /// </param> ! /// <returns>next <see cref="ExpectationMethod"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from --- 215,219 ---- /// <see cref="MethodCall"/> to get expectation for /// </param> ! /// <returns>next <see cref="IMethodCallExpectation"/></returns> /// <remarks> /// This is a state mutating method. It removes the expectation from *************** *** 221,225 **** /// exceptions. /// </remarks> ! protected virtual ExpectationMethod nextExpectation(MethodCall methodCall) { string methodName = methodCall.MethodName; --- 221,225 ---- /// exceptions. /// </remarks> ! protected virtual IMethodCallExpectation nextExpectation(MethodCall methodCall) { string methodName = methodCall.MethodName; *************** *** 237,241 **** Assertion.Fail(methodName + "() called too many times"); } ! ExpectationMethod e = (ExpectationMethod) list[0]; list.RemoveAt(0); return e; --- 237,241 ---- Assertion.Fail(methodName + "() called too many times"); } ! IMethodCallExpectation e = (IMethodCallExpectation) list[0]; list.RemoveAt(0); return e; Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ExpectationMethod.cs 19 Feb 2005 21:34:39 -0000 1.20 --- ExpectationMethod.cs 4 Mar 2005 00:18:42 -0000 1.21 *************** *** 14,18 **** /// Expected method call used for building dynamic mocks /// </summary> ! public class ExpectationMethod : AbstractExpectation { /// <summary> --- 14,19 ---- /// Expected method call used for building dynamic mocks /// </summary> ! public class ExpectationMethod : ! IMethodCallExpectation { /// <summary> *************** *** 178,182 **** /// Verifies this expectation /// </summary> ! public override void Verify() { if ( ! ActualMethodCallWasSet ) --- 179,183 ---- /// Verifies this expectation /// </summary> ! public void Verify() { if ( ! ActualMethodCallWasSet ) |