|
From: <sm...@us...> - 2003-07-30 16:57:06
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv15584/test/NMock
Modified Files:
DynamicMockTest.cs
Log Message:
Repaired borken DynamicMockTest. Still not sure what was wrong.
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** DynamicMockTest.cs 30 Jul 2003 15:02:03 -0000 1.9
--- DynamicMockTest.cs 30 Jul 2003 16:57:01 -0000 1.10
***************
*** 6,9 ****
--- 6,10 ----
namespace NMock
{
+
[TestFixture] public class DynamicMockTest : Assertion
{
***************
*** 19,23 ****
}
! class CustomMock : DynamicMock
{
public CustomMock(Type t) : base(t) {}
--- 20,24 ----
}
! private class CustomMock : DynamicMock
{
public CustomMock(Type t) : base(t) {}
***************
*** 28,55 ****
}
}
!
! class SameClass
{
public virtual string A() { return c() ? b() : "Default"; }
! protected virtual string b() { throw new AssertionException("Should not have been called"); }
protected virtual bool c() { return true; }
}
! class SameClassCaller
{
! SameClass _sameClass;
! public SameClassCaller(SameClass sc) { _sameClass = sc; }
! public virtual string CallSameClass() { return _sameClass.A(); }
}
public class Thingy
{
public void X() {}
}
-
- interface IValueType
- {
- ArrayList Query(string symbol, DateTime arg2);
- }
-
interface IOverloadedMethods
{
--- 29,48 ----
}
}
! public class SameClass
{
public virtual string A() { return c() ? b() : "Default"; }
! protected virtual string b() { throw new Exception("Should not have called b()"); }
protected virtual bool c() { return true; }
}
! interface IValueType
{
! ArrayList Query(string symbol, DateTime arg2);
}
+
public class Thingy
{
public void X() {}
}
interface IOverloadedMethods
{
***************
*** 57,79 ****
void DoStuff(string one);
}
!
! interface SomeTestInterface
{
void Foo(String a);
int Bar(String a);
}
! #endregion
!
! [Test] public void DynamicallyImplementsAnInterface()
{
! IMock mock = new DynamicMock(typeof(IBlah));
! mock.ExpectAndReturn("DoStuff", "world", "hello");
!
! IBlah blah = (IBlah)mock.MockInstance;
! Assertion.AssertEquals("world", blah.DoStuff("hello"));
!
! mock.Verify();
}
! [Test] public void HasADefaultNameBasedOnMockedType()
{
IMock mock = new DynamicMock(typeof(IBlah));
--- 50,66 ----
void DoStuff(string one);
}
! interface TwoMethods
{
void Foo(String a);
int Bar(String a);
}
! interface IWithParams
{
! void WithLeadingParameter(int i, params object[] args);
! void WithoutLeadingParameter(params object[] args);
}
! #endregion
!
! [Test] public void HasADefaultNameBasedOnMockedType()
{
IMock mock = new DynamicMock(typeof(IBlah));
***************
*** 87,90 ****
--- 74,89 ----
}
+ [Test] public void DynamicallyImplementsAnInterface()
+ {
+ IMock mock = new DynamicMock(typeof(IBlah));
+
+ mock.ExpectAndReturn("DoStuff", "world", "hello");
+
+ IBlah blah = (IBlah)mock.MockInstance;
+ Assertion.AssertEquals("world", blah.DoStuff("hello"));
+
+ mock.Verify();
+ }
+
[Test] public void CanBeCustomisedByOverridingCallMethod()
{
***************
*** 95,120 ****
}
! [Test] public void CanStubMultipleCallsToSameObject()
{
DynamicMock mock = new DynamicMock(typeof(SameClass));
mock.Ignore("A");
mock.Ignore("c");
mock.SetupResult("b", "hello");
! Assertion.AssertEquals("hello", ((SameClass)mock.MockInstance).A());
}
! [Test] public void CanSetStubsAndExpectationsOnSameObject()
{
DynamicMock mock = new DynamicMock(typeof(SameClass));
- SameClass sc = (SameClass)mock.MockInstance;
- SameClassCaller caller = new SameClassCaller(sc);
-
mock.Ignore("A");
mock.ExpectAndReturn("c", true);
mock.SetupResult("b", "hello");
! Assertion.AssertEquals("hello", caller.CallSameClass());
mock.Verify();
--- 94,119 ----
}
! [Test] public void StubbedMethodsCanBeCalledByOtherMethodsWithinObject()
{
DynamicMock mock = new DynamicMock(typeof(SameClass));
mock.Ignore("A");
mock.Ignore("c");
+ SameClass sc = (SameClass)mock.MockInstance;
+
mock.SetupResult("b", "hello");
! Assertion.AssertEquals("hello", sc.A());
}
! [Test] public void CanSetStubsAndExpectationsOnMethodsInTheSameClass()
{
DynamicMock mock = new DynamicMock(typeof(SameClass));
mock.Ignore("A");
+ SameClass sc = (SameClass)mock.MockInstance;
mock.ExpectAndReturn("c", true);
mock.SetupResult("b", "hello");
! AssertEquals("Should have overriden B()", "hello", sc.A());
mock.Verify();
***************
*** 132,148 ****
}
! [Test] public void ExpectationWillFailIfValueDoesntMatchMockInstance()
{
! DynamicMock mockThingy = new DynamicMock(typeof(Thingy));
! Thingy thingy = (Thingy)mockThingy.MockInstance;
Mock m2 = new Mock("x");
m2.Expect("y", thingy);
! try
! {
! m2.Call("y", "something else");
! Fail("Should have thrown Verify Exception");
! }
! catch (VerifyException) {};
}
--- 131,142 ----
}
! [Test] [ExpectedException(typeof(VerifyException))] public void ExpectationWillFailIfValueDoesntMatchMockInstance()
{
! DynamicMock m1 = new DynamicMock(typeof(Thingy));
! Thingy thingy = (Thingy)m1.MockInstance;
Mock m2 = new Mock("x");
m2.Expect("y", thingy);
! m2.Call("y", "something else");
}
***************
*** 150,154 ****
{
IMock mock = new DynamicMock(typeof(IValueType));
-
ArrayList ret = new ArrayList();
DateTime date = DateTime.Now;
--- 144,147 ----
***************
*** 169,175 ****
Assertion.AssertEquals("some string", b.GetSuperString());
- mock.Verify();
}
[Test] public void CanMockOverloadedMethods()
{
--- 162,185 ----
Assertion.AssertEquals("some string", b.GetSuperString());
}
+ [Test] public void CanMockMembersWithAParamsArgument()
+ {
+ IMock mock = new DynamicMock(typeof(IWithParams));
+ mock.Expect("WithLeadingParameter", 1, new Object[] {1, 2, 3});
+
+ IWithParams p = (IWithParams)mock.MockInstance;
+ p.WithLeadingParameter(1, 1, 2, 3);
+ mock.Verify();
+ }
+ [Test] [ExpectedException(typeof(MissingMethodException))] public void CannotYetMockMembersWithOnlyAParamsArgument()
+ {
+ IMock mock = new DynamicMock(typeof(IWithParams));
+ mock.Expect("WithoutLeadingParameter", new Object[] {1, 2, 3});
+
+ IWithParams p = (IWithParams)mock.MockInstance;
+ p.WithoutLeadingParameter(1, 2, 3);
+ mock.Verify();
+ }
[Test] public void CanMockOverloadedMethods()
{
***************
*** 184,194 ****
}
! [Test] public void CanSetConstraintsInExpectations()
{
! 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"));
--- 194,204 ----
}
! [Test] public void CanMockMethodWithConstraint()
{
! IMock mock = new DynamicMock(typeof(TwoMethods));
mock.Expect("Foo", new StartsWith("Hello"));
mock.ExpectAndReturn("Bar", 5, new NotNull());
! TwoMethods instance = (TwoMethods)mock.MockInstance;
instance.Foo("Hello World");
Assertion.AssertEquals("Should get a result", 5, instance.Bar("not null"));
|