|
From: <joe...@us...> - 2002-11-11 20:00:24
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory usw-pr-cvs1:/tmp/cvs-serv30478/test/NMock
Modified Files:
MockTest.cs DynamicMockTest.cs
Log Message:
Integrated some changes that have been lingering around for a while:
- mocking of self methods.
- descriptive error messages.
Index: MockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MockTest.cs 10 Nov 2002 18:21:50 -0000 1.2
--- MockTest.cs 11 Nov 2002 20:00:21 -0000 1.3
***************
*** 263,266 ****
--- 263,348 ----
mock.Call("z");
}
+
+ [Test]
+ public void ExpectNiceErrorMessageTooManyTimes()
+ {
+ try
+ {
+ mock.Expect("x");
+ mock.Expect("x");
+ mock.Call("x");
+ mock.Call("x");
+ mock.Call("x");
+ Assertion.Fail("Expected VerifyException");
+ }
+ catch (VerifyException e)
+ {
+ Assertion.AssertEquals( "x() called too many times", e.Message );
+ }
+ }
+
+ [Test]
+ [Ignore("in progress")]
+ public void ExpectNiceErrorMessageMethodNotCalledEnoughTimes()
+ {
+ try
+ {
+ mock.Expect("x");
+ mock.Verify();
+ Assertion.Fail("Expected VerifyException");
+ }
+ catch (VerifyException e)
+ {
+ Assertion.AssertEquals( "x() was not called enough times Expected:<1> Was:<0>", e.Message );
+ }
+ }
+
+ [Test]
+ public void ExpectNiceErrorMessageMethodShouldNotBeCalled()
+ {
+ try
+ {
+ mock.ExpectNoCall("x");
+ mock.Call("x", null);
+ Assertion.Fail("Expected VerifyException");
+ }
+ catch (VerifyException e)
+ {
+ Assertion.AssertEquals( "x() should not be called", e.Message );
+ }
+
+ }
+
+ [Test]
+ [Ignore("Work in progress")]
+ public void NiceErrorMessageIncorrectParameter()
+ {
+ try
+ {
+ mock.Expect("x", new object[] {1, 2, 3} );
+ mock.Call("x", new object[] {2, 3, 4});
+ Assertion.Fail("Expected VerifyException");
+ }
+ catch (VerifyException e)
+ {
+ Assertion.AssertEquals( "x() called with incorrect parameter (0) Expected:<1> Was:<2>", e.Message );
+ }
+ }
+
+ [Test]
+ public void NiceErrorMessageIncorrectNumberOfParameters()
+ {
+ try
+ {
+ mock.Expect("x", new object[] {1, 2, 3} );
+ mock.Call("x", new object[] {2, 3});
+ Assertion.Fail("Expected VerifyException");
+ }
+ catch (VerifyException e)
+ {
+ Assertion.AssertEquals( "x() called with incorrect number of parameters Expected:<3> Was:<2>", e.Message );
+ }
+ }
+
}
}
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** DynamicMockTest.cs 10 Nov 2002 16:32:27 -0000 1.1.1.1
--- DynamicMockTest.cs 11 Nov 2002 20:00:21 -0000 1.2
***************
*** 53,56 ****
--- 53,81 ----
}
}
+
+ [Test]
+ public void MockingPartsOfSameObject()
+ {
+ DynamicMock mock = new DynamicMock(typeof(SameClass));
+ mock.Ignore("A");
+ SameClass sc = (SameClass)mock.Object;
+
+ mock.SetValue("b", "hello");
+
+ Assertion.AssertEquals("hello", sc.A());
+ }
+
+ public class SameClass
+ {
+ public virtual string A()
+ {
+ return b();
+ }
+
+ protected virtual string b()
+ {
+ throw new Exception("Ouch");
+ }
+ }
}
}
|