From: Griffin C. <gc...@us...> - 2006-03-06 02:25:04
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10746/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs IMethodCallExpectation.cs Log Message: - Merged in changes from Niklas Index: IMethodCallExpectation.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IMethodCallExpectation.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IMethodCallExpectation.cs 8 Apr 2005 00:05:09 -0000 1.2 --- IMethodCallExpectation.cs 6 Mar 2006 02:24:58 -0000 1.3 *************** *** 18,21 **** --- 18,26 ---- string ExpectedMethodName { get; } + /// <summary> + /// The type of expectation, call or no call + /// </summary> + ExpectationMethodType ExpectationType { get; } + /// <summary> /// Check actual incoming method call and return expected outgoing response. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DynamicOrderedMock.cs 4 Mar 2005 00:18:42 -0000 1.12 --- DynamicOrderedMock.cs 6 Mar 2006 02:24:58 -0000 1.13 *************** *** 4,8 **** #region Imports using System; - using System.Reflection; using System.Collections; --- 4,7 ---- *************** *** 39,45 **** public override void Verify() { ! if( expectations.Count!=0 ) { ! Assertion.Fail( "Unfinished scenario: method " + ((IMethodCallExpectation)expectations[0]).ExpectedMethodName + "() wasn't called"); ! } } /// <summary> --- 38,52 ---- public override void Verify() { ! if (expectations.Count > 0) ! { ! foreach(ExpectationMethod em in expectations) ! { ! if (em.ExpectationType != ExpectationMethodType.NoCall) ! { ! Assertion.Fail("Unfinished scenario: method " + em.ExpectedMethodName + "() wasn't called"); ! } ! ! } ! } } /// <summary> *************** *** 49,52 **** --- 56,70 ---- protected override void addExpectation(IMethodCallExpectation e) { + // prevent adding a Call expectation after a NoCall expectation + if (e.ExpectationType == ExpectationMethodType.Call) + { + foreach (ExpectationMethod em in expectations) + { + if (em.ExpectationType == ExpectationMethodType.NoCall) + { + Assertion.Fail("ExpectNoCall must be last on a DynamicOrderedMock"); + } + } + } expectations.Add(e); } Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** DynamicMock.cs 8 Apr 2005 02:57:09 -0000 1.22 --- DynamicMock.cs 6 Mar 2006 02:24:58 -0000 1.23 *************** *** 117,121 **** } /// <summary> ! /// Verifies the this mock object. /// </summary> public virtual void Verify() --- 117,121 ---- } /// <summary> ! /// Verifies this mock object. /// </summary> public virtual void Verify() *************** *** 126,130 **** if ( expectationsList.Count > 0 ) { ! throw new AssertionException( expectationsList.Count + " more call(s) were expected for " + key); } } --- 126,136 ---- if ( expectationsList.Count > 0 ) { ! foreach (ExpectationMethod em in expectationsList) ! { ! if (em.ExpectationType != ExpectationMethodType.NoCall) ! { ! throw new AssertionException(expectationsList.Count + " more call(s) were expected for " + key); ! } ! } } } *************** *** 153,157 **** public virtual void ExpectNoCall(string methodName) { ! addExpectation(new ExpectationMethod(methodName, null, null, new VerifyException(methodName + "() should never be called."))); } /// <summary> --- 159,163 ---- public virtual void ExpectNoCall(string methodName) { ! addExpectation(new ExpectationMethod(methodName, null, null, new VerifyException(methodName + "() should never be called."), ExpectationMethodType.NoCall)); } /// <summary> Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** ExpectationMethod.cs 11 May 2005 05:22:22 -0000 1.26 --- ExpectationMethod.cs 6 Mar 2006 02:24:58 -0000 1.27 *************** *** 14,17 **** --- 14,33 ---- namespace DotNetMock.Dynamic { + /// <summary> + /// The kind of expectation on the method + /// </summary> + public enum ExpectationMethodType + { + /// <summary> + /// Expect the method to be called + /// </summary> + Call, + /// <summary> + /// Expect the method to not be called + /// </summary> + NoCall + }; + + /// <summary> /// Expected method call used for building dynamic mocks *************** *** 35,38 **** --- 51,59 ---- /// </summary> private Exception _expectedException; + /// <summary> + /// The type of expectation, call or no call + /// </summary> + private ExpectationMethodType _expectationType; + /// <summary> /// Actual <see cref="MethodCall"/>. *************** *** 70,102 **** { } ! /// <summary> ! /// Default Constructor ! /// </summary> ! /// <param name="methodName">Method name to expect</param> ! /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="argumentExpectations">Expectations on the arguments</param> ! /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( ! string methodName, ! object returnValue, ! object[] argumentExpectations, ! Exception expectedException ! ) ! { ! _expectedMethodName = methodName; ! _argumentExpectations = argumentExpectations; ! _expectedReturnValue = returnValue; ! _expectedException = expectedException; ! } ! /// <summary> ! /// Expected Method Name ! /// </summary> ! public string ExpectedMethodName ! { ! get ! { ! return _expectedMethodName; ! } ! } /// <summary> /// Expected Return Value --- 91,153 ---- { } ! /// <summary> ! /// Default Constructor ! /// </summary> ! /// <param name="methodName">Method name to expect</param> ! /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="argumentExpectations">Expectations on the arguments</param> ! /// <param name="expectedException">Exception to throw when called.</param> ! public ExpectationMethod( ! string methodName, ! object returnValue, ! object[] argumentExpectations, ! Exception expectedException ! ) ! : this(methodName, returnValue, argumentExpectations, expectedException, ExpectationMethodType.Call) ! { ! ! } ! /// <summary> ! /// Default Constructor ! /// </summary> ! /// <param name="methodName">Method name to expect</param> ! /// <param name="returnValue">return value when expectation is called</param> ! /// <param name="argumentExpectations">Expectations on the arguments</param> ! /// <param name="expectedException">Exception to throw when called.</param> ! /// <param name="expectationType">Type of expectation</param> ! public ExpectationMethod( ! string methodName, ! object returnValue, ! object[] argumentExpectations, ! Exception expectedException, ! ExpectationMethodType expectationType ! ) ! { ! _expectedMethodName = methodName; ! _argumentExpectations = argumentExpectations; ! _expectedReturnValue = returnValue; ! _expectedException = expectedException; ! _expectationType = expectationType; ! } ! /// <summary> ! /// Expected Method Name ! /// </summary> ! public string ExpectedMethodName ! { ! get ! { ! return _expectedMethodName; ! } ! } ! /// <summary> ! /// Expected Method Type ! /// </summary> ! public ExpectationMethodType ExpectationType ! { ! get ! { ! return _expectationType; ! } ! } /// <summary> /// Expected Return Value *************** *** 201,205 **** } /// <summary> ! /// Verifies this expectation /// </summary> public void Verify( ) --- 252,256 ---- } /// <summary> ! /// Verifies this expectation, when the method is called /// </summary> public void Verify( ) *************** *** 213,225 **** ) ); } ! if ( ExpectedMethodName != ActualMethodName ) ! { ! Assertion.Fail( String.Format( ! "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString( _argumentExpectations ), ! ActualMethodCall ! ) ); ! } ! if ( _argumentExpectations == null ) { return; --- 264,284 ---- ) ); } ! if (ExpectedMethodName != ActualMethodName && _expectationType == ExpectationMethodType.Call) ! { ! Assertion.Fail(String.Format( ! "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString(_argumentExpectations), ! ActualMethodCall ! )); ! } ! if (ExpectedMethodName == ActualMethodName && _expectationType == ExpectationMethodType.NoCall) ! { ! Assertion.Fail(String.Format( ! "{0}({1}) was not expected.", ! ExpectedMethodName, argsToString(_argumentExpectations) ! )); ! } ! ! if (_argumentExpectations == null) { return; |