Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7971/DotNetMock/Dynamic
Modified Files:
DynamicMock.cs
Log Message:
refactor extract method: factored out retrieving the next expectation for more OOAO (or DRY)
Index: DynamicMock.cs
===================================================================
RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** DynamicMock.cs 19 Feb 2005 21:34:39 -0000 1.17
--- DynamicMock.cs 19 Feb 2005 22:05:56 -0000 1.18
***************
*** 190,209 ****
return values[methodName];
}
!
! IList list = (IList) expectations[methodName];
! if (list == null)
! {
! if ( strict )
! {
! throw new VerifyException(methodName + "() called too many times");
! }
! return null;
! }
! if (list.Count == 0)
! {
! Assertion.Fail(methodName + "() called too many times");
! }
! ExpectationMethod e = (ExpectationMethod)list[0];
! list.RemoveAt(0);
e.ActualMethodCall = methodCall;
e.Verify();
--- 190,194 ----
return values[methodName];
}
! ExpectationMethod e = nextExpectation(methodName);
e.ActualMethodCall = methodCall;
e.Verify();
***************
*** 224,227 ****
--- 209,243 ----
list.Add(e);
}
+ /// <summary>
+ /// Retrieve next expectation and remove from FIFO.
+ /// </summary>
+ /// <param name="methodName">
+ /// name of method to get expectation for
+ /// </param>
+ /// <returns>next <see cref="ExpectationMethod"/></returns>
+ /// <remarks>
+ /// This is a state mutating method. It removes the expectation from
+ /// a list. Not a big deal since we don't ever recover from any
+ /// exceptions.
+ /// </remarks>
+ protected virtual ExpectationMethod nextExpectation(string methodName)
+ {
+ IList list = (IList) expectations[methodName];
+ if (list == null)
+ {
+ if ( strict )
+ {
+ throw new VerifyException(methodName + "() called too many times");
+ }
+ return null;
+ }
+ if (list.Count == 0)
+ {
+ Assertion.Fail(methodName + "() called too many times");
+ }
+ ExpectationMethod e = (ExpectationMethod) list[0];
+ list.RemoveAt(0);
+ return e;
+ }
private void generate()
|