|
From: <sm...@us...> - 2003-07-24 23:09:09
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv24112/test/NMock
Modified Files:
FastErrorHandlingTest.cs DynamicMockTest.cs MockTest.cs
Log Message:
Index: FastErrorHandlingTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/FastErrorHandlingTest.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** FastErrorHandlingTest.cs 13 Mar 2003 21:54:59 -0000 1.2
--- FastErrorHandlingTest.cs 24 Jul 2003 23:09:05 -0000 1.3
***************
*** 81,85 ****
try
{
! full.Expect("Bar");
Fail();
}
--- 81,85 ----
try
{
! full.Expect("Bar", "test");
Fail();
}
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** DynamicMockTest.cs 1 Jun 2003 09:48:49 -0000 1.7
--- DynamicMockTest.cs 24 Jul 2003 23:09:05 -0000 1.8
***************
*** 2,5 ****
--- 2,6 ----
using System;
using System.Collections;
+ using NMock.Constraints;
namespace NMock
***************
*** 65,70 ****
DynamicMock mock = new DynamicMock(typeof(SameClass));
mock.Ignore("A");
SameClass sc = (SameClass)mock.MockInstance;
!
mock.SetupResult("b", "hello");
--- 66,72 ----
DynamicMock mock = new DynamicMock(typeof(SameClass));
mock.Ignore("A");
+ mock.Ignore("c");
SameClass sc = (SameClass)mock.MockInstance;
!
mock.SetupResult("b", "hello");
***************
*** 76,80 ****
public virtual string A()
{
! return b();
}
--- 78,89 ----
public virtual string A()
{
! if(c())
! {
! return b();
! }
! else
! {
! return "Default";
! }
}
***************
*** 83,89 ****
--- 92,135 ----
throw new Exception("Ouch");
}
+
+ protected virtual bool c()
+ {
+ return true;
+ }
}
+
[Test]
+ public void MockingOnlyPartsOfACalledObjectWithNoExpectation()
+ {
+ DynamicMock mock = new DynamicMock(typeof(SameClass));
+ mock.Ignore("A");
+ SameClass sc = (SameClass)mock.MockInstance;
+ SomeCallingClass caller = new SomeCallingClass(sc);
+
+ mock.ExpectAndReturn("c", true);
+ mock.SetupResult("b", "hello");
+
+ Assertion.AssertEquals("hello", caller.CallSomeClass());
+
+ mock.Verify();
+ }
+
+ public class SomeCallingClass
+ {
+ SameClass _sameClass;
+
+ public SomeCallingClass(SameClass sc)
+ {
+ _sameClass = sc;
+ }
+
+ public virtual string CallSomeClass()
+ {
+ return _sameClass.A();
+ }
+ }
+
+ [Test]
public void MockOfClassUsedAsExpectation()
{
***************
*** 144,147 ****
--- 190,249 ----
{
public void X() {}
+ }
+
+ // [Test]
+ // public void ItIsPossibleToMockMembersWithAParamsArgument()
+ // {
+ // IMock mock = new DynamicMock(typeof(IWithParams));
+ // mock.Expect("DoStuff", new Object[] {1, 2, 3});
+ //
+ // IWithParams p = (IWithParams)mock.MockInstance;
+ // p.DoStuff(1, 2, 3);
+ //
+ // mock.Verify();
+ // }
+ //
+ // interface IWithParams
+ // {
+ // void DoStuff(params object[] args);
+ // }
+
+ interface IOverloadedMethods
+ {
+ void DoStuff(string one, int two);
+ void DoStuff(string one);
+ }
+
+ [Test]
+ public void CanMockOverloadedMethods()
+ {
+ IMock mock = new DynamicMock(typeof(IOverloadedMethods));
+ mock.Expect("DoStuff", "one", 2);
+ mock.Expect("DoStuff", "one");
+
+ IOverloadedMethods instance = (IOverloadedMethods)mock.MockInstance;
+ instance.DoStuff("one", 2);
+ instance.DoStuff("one");
+ mock.Verify();
+ }
+
+ [Test]
+ public void CanMockMethodWithConstraint()
+ {
+ IMock mock = new DynamicMock(typeof(SomeTestInterface));
+ mock.Expect("Foo", new StartsWith("Hello"));
+ mock.ExpectAndReturn("Bar", 5, new NotNull());
+
+ SomeTestInterface instance = (SomeTestInterface)mock.MockInstance;
+ instance.Foo("Hello World");
+ Assertion.AssertEquals("Should get a result", 5, instance.Bar("not null"));
+
+ mock.Verify();
+ }
+
+ interface SomeTestInterface
+ {
+ void Foo(String a);
+ int Bar(String a);
}
}
Index: MockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** MockTest.cs 13 Mar 2003 22:22:13 -0000 1.7
--- MockTest.cs 24 Jul 2003 23:09:05 -0000 1.8
***************
*** 428,432 ****
IMock Constraint = new DynamicMock(typeof(IConstraint));
Constraint.SetupResult("Message", "wee woo");
! Constraint.SetupResult("Eval", false);
mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
--- 428,432 ----
IMock Constraint = new DynamicMock(typeof(IConstraint));
Constraint.SetupResult("Message", "wee woo");
! Constraint.SetupResult("Eval", false, typeof(object));
mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
***************
*** 440,443 ****
--- 440,453 ----
Assertion.AssertEquals("world", e.Actual);
}
+ }
+
+ [Test]
+ public void ArgTypes()
+ {
+ MockCall call = new MockCall(null, null, new object[] {1, "string",
+ new bool[] {true, false}});
+ Assertion.AssertEquals("Parameter one", typeof(int), call.ArgTypes[0]);
+ Assertion.AssertEquals("Parameter two", typeof(string), call.ArgTypes[1]);
+ Assertion.AssertEquals("Parameter three", typeof(bool[]), call.ArgTypes[2]);
}
|