|
From: Levi K. <lkh...@us...> - 2004-10-13 18:04:09
|
Update of /cvsroot/nmock/nmock/test/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11257/test/NMock/Proxy Modified Files: MockRealProxyTest.cs Log Message: fixed bug with inherited/explicitly implemented interface methods Index: MockRealProxyTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/Proxy/MockRealProxyTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MockRealProxyTest.cs 13 Oct 2004 15:43:17 -0000 1.1 --- MockRealProxyTest.cs 13 Oct 2004 18:03:57 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- using System; using System.Collections; + using System.IO; using System.Reflection; using System.Reflection.Emit; *************** *** 37,54 **** string AProperty { get; set; } } public struct MyStruct ! { ! public int x; ! } ! class X ! { ! private IMock mock = null; ! string stringReturn() { return (string)mock.Invoke("stringReturn", new object[0]); } ! decimal decimalReturn() { return (decimal)mock.Invoke("decimalReturn", new object[0]); } ! MyStruct structReturn() { return (MyStruct)mock.Invoke("structReturn", new object[0]); } ! } public interface ISolidThingy --- 38,59 ---- string AProperty { get; set; } } + + public interface IDerivedThingy : IThingy + { + } public struct MyStruct ! { ! public int x; ! } ! class X ! { ! private IMock mock = null; ! string stringReturn() { return (string)mock.Invoke("stringReturn", new object[0]); } ! decimal decimalReturn() { return (decimal)mock.Invoke("decimalReturn", new object[0]); } ! MyStruct structReturn() { return (MyStruct)mock.Invoke("structReturn", new object[0]); } ! } public interface ISolidThingy *************** *** 94,97 **** --- 99,117 ---- public virtual void NoArgs() { Assertion.Fail("Should have been overriden"); } } + + public class DerivedThing : ConcreteThing + { + } + + public interface ISimpleThingy + { + void NoArgs(); + } + + public class SimpleThingy : MarshalByRefObject, ISimpleThingy + { + void ISimpleThingy.NoArgs() { Assertion.Fail("Should have been overriden"); } + } + #endregion *************** *** 196,218 **** [Test] ! public void CallMethodWithReturnDecimal() ! { ! decimal d = new decimal(3); ! mock.ExpectAndReturn("decimalReturn", d); ! decimal result = thingy.decimalReturn(); ! Assertion.AssertEquals(new decimal(3), result); ! mock.Verify(); ! } ! [Test] ! public void CallMethodWithStruct() ! { ! MyStruct str = new MyStruct(); ! str.x = 3; ! mock.ExpectAndReturn("structReturn", str); ! MyStruct result = thingy.structReturn(); ! Assertion.AssertEquals(str, result); ! mock.Verify(); ! } [Test] public void CallMethodWithReturnEnum() --- 216,238 ---- [Test] ! public void CallMethodWithReturnDecimal() ! { ! decimal d = new decimal(3); ! mock.ExpectAndReturn("decimalReturn", d); ! decimal result = thingy.decimalReturn(); ! Assertion.AssertEquals(new decimal(3), result); ! mock.Verify(); ! } ! [Test] ! public void CallMethodWithStruct() ! { ! MyStruct str = new MyStruct(); ! str.x = 3; ! mock.ExpectAndReturn("structReturn", str); ! MyStruct result = thingy.structReturn(); ! Assertion.AssertEquals(str, result); ! mock.Verify(); ! } [Test] public void CallMethodWithReturnEnum() *************** *** 224,228 **** } ! [Test] [ExpectedException(typeof(System.IO.IOException))] public void CallMethodTheThrowsException() { mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); --- 244,248 ---- } ! [Test] [ExpectedException(typeof(IOException))] public void CallMethodTheThrowsException() { mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); *************** *** 305,308 **** --- 325,358 ---- } + [Test] public void CallMethodOfImplementedInterface() + { + rp = new MockRealProxy(typeof(SimpleThingy), mock); + ISimpleThingy thingy = (ISimpleThingy)rp.GetTransparentProxy(); + + mock.SetupResult("NonVirtualProperty", "foo"); + thingy.NoArgs(); + mock.Verify(); + } + + [Test] public void CallMethodOfInheritedInterface() + { + rp = new MockRealProxy(typeof(IDerivedThingy), mock); + thingy = (IThingy)rp.GetTransparentProxy(); + + mock.Expect("NoArgs"); + thingy.NoArgs(); + mock.Verify(); + } + + [Test] public void CallMethodOfInheritedClass() + { + rp = new MockRealProxy(typeof(DerivedThing), mock); + DerivedThing derived = (DerivedThing)rp.GetTransparentProxy(); + + mock.Expect("NoArgs"); + derived.NoArgs(); + mock.Verify(); + } + [Test] public void CallReadOnlyProperty() { *************** *** 336,340 **** } ! [Test] public void CanExtendAbstractClass() { rp = new MockRealProxy(typeof(AbstractThingy), mock); --- 386,390 ---- } ! [Test] public void CanProxyAbstractClass() { rp = new MockRealProxy(typeof(AbstractThingy), mock); *************** *** 354,361 **** } ! [Test] public void CanExtendConcreteClass() { ! ConcreteThing concrete = (ConcreteThing) ! (new MockRealProxy(typeof(ConcreteThing), mock)).GetTransparentProxy(); mock.Expect("NoArgs"); --- 404,411 ---- } ! [Test] public void CanProxyConcreteClass() { ! rp = new MockRealProxy(typeof(ConcreteThing), mock); ! ConcreteThing concrete = (ConcreteThing)rp.GetTransparentProxy(); mock.Expect("NoArgs"); |