|
From: <joe...@us...> - 2002-11-11 20:00:24
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory usw-pr-cvs1:/tmp/cvs-serv30478/src/NMock
Modified Files:
DynamicMock.cs Mock.cs
Log Message:
Integrated some changes that have been lingering around for a while:
- mocking of self methods.
- descriptive error messages.
Index: DynamicMock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** DynamicMock.cs 10 Nov 2002 16:32:27 -0000 1.1.1.1
--- DynamicMock.cs 11 Nov 2002 20:00:19 -0000 1.2
***************
*** 1,3 ****
--- 1,4 ----
using System;
+ using System.Collections;
using NMock.Dynamic;
***************
*** 9,16 ****
--- 10,19 ----
private object obj;
private Type type;
+ private IList ignore;
public DynamicMock(Type type) : this(type, null)
{
string name = type.Name;
+ ignore = new ArrayList();
if (name.StartsWith("I"))
{
***************
*** 37,44 ****
}
private void generate()
{
ClassGenerator cg = new ClassGenerator();
! obj = cg.Generate(type, this);
}
}
--- 40,55 ----
}
+ /// <summary>
+ /// Don't generate mock method for suppied methodName.
+ /// </summary>
+ public virtual void Ignore(string methodName)
+ {
+ ignore.Add(methodName);
+ }
+
private void generate()
{
ClassGenerator cg = new ClassGenerator();
! obj = cg.Generate(type, this, ignore);
}
}
Index: Mock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Mock.cs 10 Nov 2002 18:21:50 -0000 1.2
--- Mock.cs 11 Nov 2002 20:00:20 -0000 1.3
***************
*** 41,47 ****
public virtual void Verify()
{
! foreach (IList list in expectations.Values)
{
! Assertion.AssertEquals(0, list.Count);
}
}
--- 41,48 ----
public virtual void Verify()
{
! foreach (String methodName in expectations.Keys)
{
! IList list = (IList) expectations[methodName];
! Assertion.AssertEquals(methodName + "() was not called enough times", 0, list.Count);
}
}
***************
*** 54,58 ****
public virtual void ExpectNoCall(string methodName)
{
! addExpectation(new Expectation(methodName, null, new VerifyException(methodName + "() should never be called."), null));
}
--- 55,59 ----
public virtual void ExpectNoCall(string methodName)
{
! addExpectation(new Expectation(methodName, null, new VerifyException(methodName + "() should not be called"), null));
}
***************
*** 135,160 ****
Assertion.AssertEquals(this.MethodName, methodName);
! // assert that each passed in arg is validated by the appropriate condition.
! for (int i = 0; i < this.args.Length; i++)
{
! object expectedArg = this.args[i];
! object actualArg = args[i];
! ICondition condition = expectedArg as ICondition;
!
! // if expectedArg is not an ICondition, use default
! // behavior of IsEqual or IsAnything
! if (condition == null)
{
! if (expectedArg == null)
! {
! condition = new IsAnything();
! }
! else
{
! condition = new IsEqual(expectedArg);
}
}
-
- Assertion.Assert(condition.eval(actualArg));
}
--- 136,169 ----
Assertion.AssertEquals(this.MethodName, methodName);
! if ( this.args.Length > 0 )
{
! // assert that the correct number of arguments were passed
! Assertion.AssertEquals("x() called with incorrect number of parameters", this.args.Length, args.Length);
!
! // assert that each passed in arg is validated by the appropriate predicate.
! for (int i = 0; i < this.args.Length; i++)
{
! object expectedArg = this.args[i];
! object actualArg = args[i];
! ICondition condition = expectedArg as ICondition;
!
! // if expectedArg is not an ICondition, use default
! // behavior of IsEqual or IsAnything
! if (condition == null)
{
! if (expectedArg == null)
! {
! condition = new IsAnything();
! }
! else
! {
! condition = new IsEqual(expectedArg);
! }
}
+ String messageFormat = "{0}() called with incorrect parameter ({1}) Expected:<{2}> Was:<{3}>";
+ //String message = String.Format(messageFormat, methodName, i, condition.Description, actualArg);
+ String message = String.Format(messageFormat, methodName, i, "fixme", actualArg);
+ Assertion.Assert(message, condition.eval(actualArg));
}
}
***************
*** 171,179 ****
private class Assertion
{
! public static void Assert(bool expression)
{
if (!expression)
{
! Fail("Verification failed.");
}
}
--- 180,188 ----
private class Assertion
{
! public static void Assert(string message, bool expression)
{
if (!expression)
{
! Fail(message);
}
}
***************
*** 181,187 ****
public static void AssertEquals(object a, object b)
{
if (! a.Equals(b))
{
! Fail("Verification failed.");
}
}
--- 190,202 ----
public static void AssertEquals(object a, object b)
{
+ AssertEquals("Verification failed", a, b);
+ }
+
+ public static void AssertEquals(string message, object a, object b)
+ {
if (! a.Equals(b))
{
! String messageFormat = "{0} Expected:<{1}> Was:<{2}>";
! Fail(String.Format(messageFormat, message, a, b));
}
}
|