|
From: <sm...@us...> - 2003-07-30 15:02:06
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv27230/test/NMock
Modified Files:
DynamicMockTest.cs
Log Message:
Reformatted to make code folding in VisualStudio work better
Renamed test methods to be more descriptive
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** DynamicMockTest.cs 24 Jul 2003 23:09:05 -0000 1.8
--- DynamicMockTest.cs 30 Jul 2003 15:02:03 -0000 1.9
***************
*** 6,13 ****
namespace NMock
{
!
! [TestFixture]
! public class DynamicMockTest
{
interface IBaseBlah
{
--- 6,12 ----
namespace NMock
{
! [TestFixture] public class DynamicMockTest : Assertion
{
+ #region types
interface IBaseBlah
{
***************
*** 20,29 ****
}
! [Test]
! public void DefaultDynamicMock()
{
! IMock mock = new DynamicMock(typeof(IBlah));
! Assertion.AssertEquals("MockIBlah", mock.Name);
mock.ExpectAndReturn("DoStuff", "world", "hello");
--- 19,71 ----
}
! class CustomMock : DynamicMock
{
! public CustomMock(Type t) : base(t) {}
+ public override object Call(string name, params object[] args)
+ {
+ return "CUSTOM";
+ }
+ }
+
+ 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
+ {
+ void DoStuff(string one, int two);
+ 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");
***************
*** 33,47 ****
mock.Verify();
}
! [Test]
! public void NamedDynamicMock()
{
IMock mock = new DynamicMock(typeof(IBlah), "XBlah");
Assertion.AssertEquals("XBlah", mock.Name);
- mock.Verify();
}
! [Test]
! public void CustomDynamicMock()
{
IMock mock = new CustomMock(typeof(IBlah));
--- 75,91 ----
mock.Verify();
}
+ [Test] public void HasADefaultNameBasedOnMockedType()
+ {
+ IMock mock = new DynamicMock(typeof(IBlah));
+ Assertion.AssertEquals("MockIBlah", mock.Name);
+ }
! [Test] public void CanBeExplicitlyNamed()
{
IMock mock = new DynamicMock(typeof(IBlah), "XBlah");
Assertion.AssertEquals("XBlah", mock.Name);
}
! [Test] public void CanBeCustomisedByOverridingCallMethod()
{
IMock mock = new CustomMock(typeof(IBlah));
***************
*** 51,164 ****
}
! private class CustomMock : DynamicMock
! {
! public CustomMock(Type t) : base(t) {}
!
! public override object Call(string name, params object[] args)
! {
! return "CUSTOM";
! }
! }
!
! [Test]
! public void MockingPartsOfSameObject()
{
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());
! }
!
! public class SameClass
! {
! public virtual string A()
! {
! if(c())
! {
! return b();
! }
! else
! {
! return "Default";
! }
! }
!
! protected virtual string b()
! {
! 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()
{
! DynamicMock m1 = new DynamicMock(typeof(Thingy));
! Thingy b = (Thingy)m1.MockInstance;
Mock m2 = new Mock("x");
! m2.Expect("y", b);
! m2.Call("y", b);
m2.Verify();
}
! [Test]
! [ExpectedException(typeof(VerifyException))]
! public void MockOfClassUsedAsFailedExpectation()
{
! DynamicMock m1 = new DynamicMock(typeof(Thingy));
! Thingy b = (Thingy)m1.MockInstance;
Mock m2 = new Mock("x");
! m2.Expect("y", b);
! m2.Call("y", "something else");
! m2.Verify();
}
! [Test]
! public void ValueType()
{
IMock mock = new DynamicMock(typeof(IValueType));
! Assertion.AssertEquals("MockIValueType", mock.Name);
ArrayList ret = new ArrayList();
DateTime date = DateTime.Now;
--- 95,154 ----
}
! [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();
}
! [Test] public void MockInstanceCanBeUsedAsValueInAnExpectation()
{
! DynamicMock mockThingy = new DynamicMock(typeof(Thingy));
! Thingy thingy = (Thingy)mockThingy.MockInstance;
Mock m2 = new Mock("x");
! m2.Expect("y", thingy);
! m2.Call("y", thingy);
m2.Verify();
}
! [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) {};
}
! [Test] public void CanExpectMultipleInputsAndReturnAValue()
{
IMock mock = new DynamicMock(typeof(IValueType));
!
ArrayList ret = new ArrayList();
DateTime date = DateTime.Now;
***************
*** 171,176 ****
}
! [Test]
! public void MockingMembersFromBaseInterfaces()
{
IMock mock = new DynamicMock(typeof(IBlah));
--- 161,165 ----
}
! [Test] public void CanMockMembersInheritedFromBaseInterfaces()
{
IMock mock = new DynamicMock(typeof(IBlah));
***************
*** 180,220 ****
Assertion.AssertEquals("some string", b.GetSuperString());
}
! interface IValueType
! {
! ArrayList Query(string symbol, DateTime arg2);
! }
!
! public class Thingy
! {
! 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));
--- 169,176 ----
Assertion.AssertEquals("some string", b.GetSuperString());
+ mock.Verify();
}
! [Test] public void CanMockOverloadedMethods()
{
IMock mock = new DynamicMock(typeof(IOverloadedMethods));
***************
*** 228,233 ****
}
! [Test]
! public void CanMockMethodWithConstraint()
{
IMock mock = new DynamicMock(typeof(SomeTestInterface));
--- 184,188 ----
}
! [Test] public void CanSetConstraintsInExpectations()
{
IMock mock = new DynamicMock(typeof(SomeTestInterface));
***************
*** 242,250 ****
}
- interface SomeTestInterface
- {
- void Foo(String a);
- int Bar(String a);
- }
}
}
--- 197,200 ----
|