Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16061/DotNetMock/Dynamic
Modified Files:
ExpectationMethod.cs
Log Message:
Provide name of argument that did not satisfy predicate in AssertionException.
Index: ExpectationMethod.cs
===================================================================
RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** ExpectationMethod.cs 18 Feb 2005 00:41:52 -0000 1.15
--- ExpectationMethod.cs 18 Feb 2005 02:16:08 -0000 1.16
***************
*** 190,193 ****
--- 190,218 ----
));
}
+ // check if the actual argument count is correct
+ // TODO: ideally this would be done in the constructor if possible
+ ParameterInfo[] pis = ActualMethod.GetParameters();
+ if ( pis.Length!=_actualMethodArguments.Length )
+ {
+ throw new InvalidOperationException(String.Format(
+ "Method {0} takes {1} arguments but received {2}.",
+ ActualMethodName,
+ pis.Length,
+ _actualMethodArguments.Length
+ ));
+ }
+ /* cannot check that actual args size matches expected
+ * because we want to be able to expect using just method name
+ if ( _actualMethodArguments.Length!=_expectedMethodArguments.Length)
+ {
+ Assertion.Fail(String.Format(
+ "Expected {0} arguments but received {1} "+
+ "in method call {2}({3}).",
+ _expectedMethodArguments.Length,
+ _actualMethodArguments.Length,
+ ActualMethodName, argsToString(_actualMethodArguments)
+ ));
+ }
+ */
// assert that each passed in arg is validated by the appropriate predicate.
***************
*** 195,212 ****
{
object argumentExpectation = _expectedMethodArguments[i];
! object actualArg = _actualMethodArguments[i];
// evaluate whether input expectations have been met
IPredicate predicate =
PredicateUtils.ConvertFrom(argumentExpectation);
! // wasteful but good as a first cut at better error messages
! string failureMessage = String.Format(
! "Failed to satisfy '{0}' on argument {1} of method call {2}({3})",
! predicate,
! i,
! ExpectedMethodName,
! argsToString(_actualMethodArguments)
! );
! Assertion.Assert(failureMessage, predicate.Eval(actualArg));
// return output expectations if specified
IArgumentMutator mutator =
--- 220,243 ----
{
object argumentExpectation = _expectedMethodArguments[i];
! object actualArgument = _actualMethodArguments[i];
// evaluate whether input expectations have been met
IPredicate predicate =
PredicateUtils.ConvertFrom(argumentExpectation);
! bool isPredicateSatisfied =
! predicate.Eval(actualArgument);
! if ( ! isPredicateSatisfied )
! {
! ParameterInfo pi = pis[i];
! Assertion.Fail(String.Format(
! "Failed to satisfy '{0}' on argument {2} ({1}) "+
! "of method call {3}({4})",
! predicate,
! pi.Name,
! i,
! ExpectedMethodName,
! argsToString(_actualMethodArguments)
! ));
! }
// return output expectations if specified
IArgumentMutator mutator =
|