|
From: Owen R. <exo...@us...> - 2004-10-22 11:47:09
|
Update of /cvsroot/nmock/nmock/test/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19470/test/NMock/Proxy Modified Files: MockRealProxyTest.cs Log Message: upgraded to nunit 2.2 upgraded to new version of NAnt Index: MockRealProxyTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/Proxy/MockRealProxyTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MockRealProxyTest.cs 13 Oct 2004 18:03:57 -0000 1.2 --- MockRealProxyTest.cs 22 Oct 2004 11:46:28 -0000 1.3 *************** *** 2,17 **** using System.Collections; using System.IO; - using System.Reflection; - using System.Reflection.Emit; - - - using NUnit.Framework; - using NMock; using NMock.Constraints; namespace NMock.Proxy { #region types ! public interface IThingy { void NoArgs(); --- 2,14 ---- using System.Collections; using System.IO; using NMock.Constraints; + using NUnit.Framework; namespace NMock.Proxy { + #region types ! ! public interface IThingy { void NoArgs(); *************** *** 42,60 **** { } ! ! 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 { --- 39,68 ---- { } ! ! public struct MyStruct { public int x; } ! ! internal class X { private IMock mock = null; ! ! private string stringReturn() ! { ! return (string) mock.Invoke("stringReturn", new object[0]); ! } ! ! private decimal decimalReturn() ! { ! return (decimal) mock.Invoke("decimalReturn", new object[0]); ! } ! ! private MyStruct structReturn() ! { ! return (MyStruct) mock.Invoke("structReturn", new object[0]); ! } } ! public interface ISolidThingy { *************** *** 65,80 **** { // internal and protected internal methods must be overridable! ! public virtual string VirtualMethod() { return "xx"; } public abstract string AbstractMethod(); ! protected internal virtual string ProtectedInternalMethod() { return "xx"; } // cannot override ! public static string StaticMethod() { return "xx"; } ! public string NonVirtualMethod() { return "xx"; } ! internal string NonVirtualInternalMethod() { return "xx"; } ! private string privateMethod() { return "xx"; } ! protected virtual string protectedMethod() { return "xx"; } ! string defaultInternalMethod() { return "xx"; } ! public override string ToString() { return "xx"; } // method is ignored // implemented interface members/methods are defined as final (ie. non-virtual) --- 73,123 ---- { // internal and protected internal methods must be overridable! ! public virtual string VirtualMethod() ! { ! return "xx"; ! } ! public abstract string AbstractMethod(); ! ! protected internal virtual string ProtectedInternalMethod() ! { ! return "xx"; ! } // cannot override ! public static string StaticMethod() ! { ! return "xx"; ! } ! ! public string NonVirtualMethod() ! { ! return "xx"; ! } ! ! internal string NonVirtualInternalMethod() ! { ! return "xx"; ! } ! ! private string privateMethod() ! { ! return "xx"; ! } ! ! protected virtual string protectedMethod() ! { ! return "xx"; ! } ! ! private string defaultInternalMethod() ! { ! return "xx"; ! } ! ! public override string ToString() ! { ! return "xx"; ! } // method is ignored // implemented interface members/methods are defined as final (ie. non-virtual) *************** *** 85,101 **** } ! public class ClassWithInternalMethod { ! internal virtual string InternalMethod() { return "xx"; } } ! public enum MyEnum { ! A, B, C, D } public class ConcreteThing : MarshalByRefObject { ! public virtual void NoArgs() { Assertion.Fail("Should have been overriden"); } } --- 128,153 ---- } ! public class ClassWithInternalMethod { ! internal virtual string InternalMethod() ! { ! return "xx"; ! } } ! public enum MyEnum { ! A, ! B, ! C, ! D } public class ConcreteThing : MarshalByRefObject { ! public virtual void NoArgs() ! { ! Assert.Fail("Should have been overriden"); ! } } *************** *** 111,130 **** public class SimpleThingy : MarshalByRefObject, ISimpleThingy { ! void ISimpleThingy.NoArgs() { Assertion.Fail("Should have been overriden"); } } #endregion ! [TestFixture] public class MockRealProxyInvocationHandlerTest { ! public class InvocationHandlerImpl : IInvocationHandler { public string expectedMethodName; public bool wasCalled = false; ! public object Invoke(string methodName, params object[] args) { ! Assertion.AssertEquals("should be method name", expectedMethodName, methodName); ! Assertion.AssertEquals("Should be no args", 0, args.Length); wasCalled = true; return null; --- 163,186 ---- public class SimpleThingy : MarshalByRefObject, ISimpleThingy { ! void ISimpleThingy.NoArgs() ! { ! Assert.Fail("Should have been overriden"); ! } } #endregion ! [TestFixture] ! public class MockRealProxyInvocationHandlerTest { ! public class InvocationHandlerImpl : IInvocationHandler { public string expectedMethodName; public bool wasCalled = false; ! public object Invoke(string methodName, params object[] args) { ! Assert.AreEqual(expectedMethodName, methodName, "should be method name"); ! Assert.AreEqual(0, args.Length, "Should be no args"); wasCalled = true; return null; *************** *** 137,168 **** } ! [Test] public void CreateRealProxy() { InvocationHandlerImpl handler = new InvocationHandlerImpl(); ! MockRealProxy rp = new MockRealProxy(typeof(IThingy), handler); ! IThingy thingy = (IThingy)rp.GetTransparentProxy(); ! handler.expectedMethodName = "NoArgs"; thingy.NoArgs(); ! Assertion.Assert("Should have been called ", handler.wasCalled); } } ! [TestFixture] public class MockRealProxyTest { private MockRealProxy rp; private IMock mock; private IThingy thingy; ! ! [SetUp] public void SetUp() { mock = new Mock("Test Mock"); ! rp = new MockRealProxy(typeof(IThingy), mock); ! thingy = (IThingy)rp.GetTransparentProxy(); } ! [Test] public void CallMethodIsCalled() { mock.Expect("NoArgs"); --- 193,228 ---- } ! [Test] ! public void CreateRealProxy() { InvocationHandlerImpl handler = new InvocationHandlerImpl(); ! MockRealProxy rp = new MockRealProxy(typeof (IThingy), handler); ! IThingy thingy = (IThingy) rp.GetTransparentProxy(); ! handler.expectedMethodName = "NoArgs"; thingy.NoArgs(); ! Assert.IsTrue(handler.wasCalled, "Should have been called "); } } ! [TestFixture] ! public class MockRealProxyTest { private MockRealProxy rp; private IMock mock; private IThingy thingy; ! ! [SetUp] ! public void SetUp() { mock = new Mock("Test Mock"); ! rp = new MockRealProxy(typeof (IThingy), mock); ! thingy = (IThingy) rp.GetTransparentProxy(); } ! [Test] ! public void CallMethodIsCalled() { mock.Expect("NoArgs"); *************** *** 171,230 **** } ! [Test] public void CallMethodWithReturn() { object x = "sdfs"; mock.ExpectAndReturn("simpleReturn", x); object result = thingy.simpleReturn(); ! Assertion.AssertEquals(x, result); mock.Verify(); } ! [Test] public void CallMethodWithReturnAndCast() { string x = "sdfs"; mock.ExpectAndReturn("stringReturn", x); string result = thingy.stringReturn(); ! Assertion.AssertEquals(x, result); mock.Verify(); } ! [Test] public void CallMethodWithWeirdObjectReturn() { IThingy t = thingy; mock.ExpectAndReturn("AThingy", t); IThingy result = thingy.AThingy(); ! Assertion.AssertSame(thingy, result); mock.Verify(); } ! [Test] public void CallMethodWithReturnInt() { mock.ExpectAndReturn("intReturn", 7); int result = thingy.intReturn(); ! Assertion.AssertEquals(7, result); mock.Verify(); } ! [Test] public void CallMethodWithReturnBoxings() { mock.ExpectAndReturn("boolReturn", true); mock.ExpectAndReturn("doubleReturn", 1234567891234E+10); ! Assertion.Assert(thingy.boolReturn()); ! Assertion.AssertEquals(1234567891234E+10, thingy.doubleReturn()); mock.Verify(); } ! [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(); --- 231,295 ---- } ! [Test] ! public void CallMethodWithReturn() { object x = "sdfs"; mock.ExpectAndReturn("simpleReturn", x); object result = thingy.simpleReturn(); ! Assert.AreEqual(x, result); mock.Verify(); } ! [Test] ! public void CallMethodWithReturnAndCast() { string x = "sdfs"; mock.ExpectAndReturn("stringReturn", x); string result = thingy.stringReturn(); ! Assert.AreEqual(x, result); mock.Verify(); } ! [Test] ! public void CallMethodWithWeirdObjectReturn() { IThingy t = thingy; mock.ExpectAndReturn("AThingy", t); IThingy result = thingy.AThingy(); ! Assert.AreSame(thingy, result); mock.Verify(); } ! [Test] ! public void CallMethodWithReturnInt() { mock.ExpectAndReturn("intReturn", 7); int result = thingy.intReturn(); ! Assert.AreEqual(7, result); mock.Verify(); } ! [Test] ! public void CallMethodWithReturnBoxings() { mock.ExpectAndReturn("boolReturn", true); mock.ExpectAndReturn("doubleReturn", 1234567891234E+10); ! Assert.IsTrue(thingy.boolReturn()); ! Assert.AreEqual(1234567891234E+10, thingy.doubleReturn()); mock.Verify(); } ! [Test] ! public void CallMethodWithReturnDecimal() { decimal d = new decimal(3); mock.ExpectAndReturn("decimalReturn", d); decimal result = thingy.decimalReturn(); ! Assert.AreEqual(new decimal(3), result); mock.Verify(); } ! [Test] ! public void CallMethodWithStruct() { MyStruct str = new MyStruct(); *************** *** 232,254 **** mock.ExpectAndReturn("structReturn", str); MyStruct result = thingy.structReturn(); ! Assertion.AssertEquals(str, result); mock.Verify(); ! } ! ! [Test] public void CallMethodWithReturnEnum() { mock.ExpectAndReturn("getEnum", MyEnum.C); MyEnum result = thingy.getEnum(); ! Assertion.AssertEquals(MyEnum.C, result); mock.Verify(); } ! ! [Test] [ExpectedException(typeof(IOException))] public void CallMethodTheThrowsException() { ! mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); thingy.boolReturn(); } ! [Test] public void CallMethodWithStringParameterExpectation() { mock.Expect("WithSimpleArg", new StartsWith("he")); --- 297,323 ---- mock.ExpectAndReturn("structReturn", str); MyStruct result = thingy.structReturn(); ! Assert.AreEqual(str, result); mock.Verify(); ! } ! ! [Test] ! public void CallMethodWithReturnEnum() { mock.ExpectAndReturn("getEnum", MyEnum.C); MyEnum result = thingy.getEnum(); ! Assert.AreEqual(MyEnum.C, result); mock.Verify(); } ! ! [Test] ! [ExpectedException(typeof (IOException))] ! public void CallMethodTheThrowsException() { ! mock.ExpectAndThrow("boolReturn", new IOException()); thingy.boolReturn(); } ! [Test] ! public void CallMethodWithStringParameterExpectation() { mock.Expect("WithSimpleArg", new StartsWith("he")); *************** *** 256,261 **** mock.Verify(); } ! ! [Test] public void CallMethodWithStringParameter() { mock.Expect("WithSimpleArg", "hello"); --- 325,331 ---- mock.Verify(); } ! ! [Test] ! public void CallMethodWithStringParameter() { mock.Expect("WithSimpleArg", "hello"); *************** *** 264,274 **** } ! [Test] public void CallMethodWithIntParameter() { mock.Expect("WithIntParam", 1); thingy.WithIntParam(1); mock.Verify(); ! } ! [Test] [ExpectedException(typeof(VerifyException))] public void CallMethodWithParamExpectationsThatFails() { mock.Expect("WithSimpleArg", new IsEqual("hello")); --- 334,348 ---- } ! [Test] ! public void CallMethodWithIntParameter() { mock.Expect("WithIntParam", 1); thingy.WithIntParam(1); mock.Verify(); ! } ! ! [Test] ! [ExpectedException(typeof (VerifyException))] ! public void CallMethodWithParamExpectationsThatFails() { mock.Expect("WithSimpleArg", new IsEqual("hello")); *************** *** 276,281 **** mock.Verify(); } ! ! [Test] public void CallMethodWithTwoParamExpectations() { mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); --- 350,356 ---- mock.Verify(); } ! ! [Test] ! public void CallMethodWithTwoParamExpectations() { mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); *************** *** 283,288 **** mock.Verify(); } ! ! [Test] [ExpectedException(typeof(VerifyException))] public void CallMethodWithTwoParamExpectationsThatFails() { mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); --- 358,365 ---- mock.Verify(); } ! ! [Test] ! [ExpectedException(typeof (VerifyException))] ! public void CallMethodWithTwoParamExpectationsThatFails() { mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); *************** *** 290,295 **** mock.Verify(); } ! ! [Test] public void CallMethodWithThreeParamExpectations() { mock.Expect("WithThreeArgs", new IsEqual("hello"), new IsEqual("the"), new IsEqual("world")); --- 367,373 ---- mock.Verify(); } ! ! [Test] ! public void CallMethodWithThreeParamExpectations() { mock.Expect("WithThreeArgs", new IsEqual("hello"), new IsEqual("the"), new IsEqual("world")); *************** *** 297,302 **** mock.Verify(); } ! ! [Test] public void CallMethodWithLotsOfArgsExpectations() { mock.Expect("WithLotsOfArgs", new IsEqual("hello"), new IsEqual("world"), new IsEqual("is"), new IsEqual("this"), new IsEqual("the"), new IsEqual("end")); --- 375,381 ---- mock.Verify(); } ! ! [Test] ! public void CallMethodWithLotsOfArgsExpectations() { mock.Expect("WithLotsOfArgs", new IsEqual("hello"), new IsEqual("world"), new IsEqual("is"), new IsEqual("this"), new IsEqual("the"), new IsEqual("end")); *************** *** 305,309 **** } ! [Test] public void CallMethodWithOtherArgs() { IList l = new ArrayList(); --- 384,389 ---- } ! [Test] ! public void CallMethodWithOtherArgs() { IList l = new ArrayList(); *************** *** 312,322 **** mock.Verify(); } ! [Test] public void CallMethodWithVariableNumberOfParams() { ! mock.Expect("WithParams", 1, new object[]{"string1", "string2"}); thingy.WithParams(1, "string1", "string2"); mock.Verify(); } ! [Test] public void CallMethodWithLongParam() { mock.Expect("WithLongParam", 5L); --- 392,406 ---- mock.Verify(); } ! ! [Test] ! public void CallMethodWithVariableNumberOfParams() { ! mock.Expect("WithParams", 1, new object[] {"string1", "string2"}); thingy.WithParams(1, "string1", "string2"); mock.Verify(); } ! ! [Test] ! public void CallMethodWithLongParam() { mock.Expect("WithLongParam", 5L); *************** *** 325,332 **** } ! [Test] public void CallMethodOfImplementedInterface() { ! rp = new MockRealProxy(typeof(SimpleThingy), mock); ! ISimpleThingy thingy = (ISimpleThingy)rp.GetTransparentProxy(); mock.SetupResult("NonVirtualProperty", "foo"); --- 409,417 ---- } ! [Test] ! public void CallMethodOfImplementedInterface() { ! rp = new MockRealProxy(typeof (SimpleThingy), mock); ! ISimpleThingy thingy = (ISimpleThingy) rp.GetTransparentProxy(); mock.SetupResult("NonVirtualProperty", "foo"); *************** *** 335,342 **** } ! [Test] public void CallMethodOfInheritedInterface() { ! rp = new MockRealProxy(typeof(IDerivedThingy), mock); ! thingy = (IThingy)rp.GetTransparentProxy(); mock.Expect("NoArgs"); --- 420,428 ---- } ! [Test] ! public void CallMethodOfInheritedInterface() { ! rp = new MockRealProxy(typeof (IDerivedThingy), mock); ! thingy = (IThingy) rp.GetTransparentProxy(); mock.Expect("NoArgs"); *************** *** 345,352 **** } ! [Test] public void CallMethodOfInheritedClass() { ! rp = new MockRealProxy(typeof(DerivedThing), mock); ! DerivedThing derived = (DerivedThing)rp.GetTransparentProxy(); mock.Expect("NoArgs"); --- 431,439 ---- } ! [Test] ! public void CallMethodOfInheritedClass() { ! rp = new MockRealProxy(typeof (DerivedThing), mock); ! DerivedThing derived = (DerivedThing) rp.GetTransparentProxy(); mock.Expect("NoArgs"); *************** *** 355,368 **** } ! [Test] public void CallReadOnlyProperty() { mock.ExpectAndReturn("ReadProperty", "hello"); mock.ExpectAndReturn("ReadProperty", "world"); ! Assertion.AssertEquals("hello", thingy.ReadProperty); ! Assertion.AssertEquals("world", thingy.ReadProperty); mock.Verify(); } ! [Test] public void WriteOnlyPropertyExpectations() { mock.Expect("WriteProperty", "hello"); --- 442,457 ---- } ! [Test] ! public void CallReadOnlyProperty() { mock.ExpectAndReturn("ReadProperty", "hello"); mock.ExpectAndReturn("ReadProperty", "world"); ! Assert.AreEqual("hello", thingy.ReadProperty); ! Assert.AreEqual("world", thingy.ReadProperty); mock.Verify(); } ! [Test] ! public void WriteOnlyPropertyExpectations() { mock.Expect("WriteProperty", "hello"); *************** *** 373,377 **** } ! [Test] public void ReadAndWriteProperty() { mock.Expect("AProperty", "hello"); --- 462,467 ---- } ! [Test] ! public void ReadAndWriteProperty() { mock.Expect("AProperty", "hello"); *************** *** 381,393 **** thingy.AProperty = "hello"; thingy.AProperty = "world"; ! Assertion.AssertEquals("good", thingy.AProperty); ! Assertion.AssertEquals("bye", thingy.AProperty); mock.Verify(); } ! [Test] public void CanProxyAbstractClass() { ! rp = new MockRealProxy(typeof(AbstractThingy), mock); ! AbstractThingy s = (AbstractThingy)rp.GetTransparentProxy(); mock.ExpectAndReturn("VirtualMethod", "hello"); --- 471,484 ---- thingy.AProperty = "hello"; thingy.AProperty = "world"; ! Assert.AreEqual("good", thingy.AProperty); ! Assert.AreEqual("bye", thingy.AProperty); mock.Verify(); } ! [Test] ! public void CanProxyAbstractClass() { ! rp = new MockRealProxy(typeof (AbstractThingy), mock); ! AbstractThingy s = (AbstractThingy) rp.GetTransparentProxy(); mock.ExpectAndReturn("VirtualMethod", "hello"); *************** *** 396,411 **** mock.ExpectAndReturn("ProtectedInternalMethod", "white"); ! Assertion.AssertEquals("hello", s.VirtualMethod()); ! Assertion.AssertEquals(123, s.GetHashCode()); ! Assertion.AssertEquals("fish", s.AbstractMethod()); ! Assertion.AssertEquals("white", s.ProtectedInternalMethod()); mock.Verify(); } ! [Test] public void CanProxyConcreteClass() { ! rp = new MockRealProxy(typeof(ConcreteThing), mock); ! ConcreteThing concrete = (ConcreteThing)rp.GetTransparentProxy(); mock.Expect("NoArgs"); --- 487,503 ---- mock.ExpectAndReturn("ProtectedInternalMethod", "white"); ! Assert.AreEqual("hello", s.VirtualMethod()); ! Assert.AreEqual(123, s.GetHashCode()); ! Assert.AreEqual("fish", s.AbstractMethod()); ! Assert.AreEqual("white", s.ProtectedInternalMethod()); mock.Verify(); } ! [Test] ! public void CanProxyConcreteClass() { ! rp = new MockRealProxy(typeof (ConcreteThing), mock); ! ConcreteThing concrete = (ConcreteThing) rp.GetTransparentProxy(); mock.Expect("NoArgs"); *************** *** 414,434 **** } ! [Test] public void CanHandleNonVirtualFeatures() { ! rp = new MockRealProxy(typeof(AbstractThingy), mock); ! AbstractThingy s = (AbstractThingy)rp.GetTransparentProxy(); mock.SetupResult("NonVirtualMethod", "non virtual method"); mock.SetupResult("NonVirtualProperty", "non virtual property"); ! Assertion.AssertEquals("non virtual method", s.NonVirtualMethod()); ! Assertion.AssertEquals("non virtual property", s.NonVirtualProperty); mock.Verify(); } ! [Test] public void CanHandleObjectMethodOnInterface() { ! Assertion.AssertNull(thingy.ToString()); } } ! } --- 506,528 ---- } ! [Test] ! public void CanHandleNonVirtualFeatures() { ! rp = new MockRealProxy(typeof (AbstractThingy), mock); ! AbstractThingy s = (AbstractThingy) rp.GetTransparentProxy(); mock.SetupResult("NonVirtualMethod", "non virtual method"); mock.SetupResult("NonVirtualProperty", "non virtual property"); ! Assert.AreEqual("non virtual method", s.NonVirtualMethod()); ! Assert.AreEqual("non virtual property", s.NonVirtualProperty); mock.Verify(); } ! [Test] ! public void CanHandleObjectMethodOnInterface() { ! Assert.IsNull(thingy.ToString()); } } ! } \ No newline at end of file |