From: Joe W. <joe...@us...> - 2002-10-07 00:08:06
|
Update of /cvsroot/mockobjects/nmock/test/NMock/Dynamic In directory usw-pr-cvs1:/tmp/cvs-serv28357/test/NMock/Dynamic Modified Files: ClassGeneratorTest.cs Log Message: ClassGenerator can now create dynamic mocks based on classes as well as interfaces (although it can only override virtual methods). Index: ClassGeneratorTest.cs =================================================================== RCS file: /cvsroot/mockobjects/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClassGeneratorTest.cs 6 Oct 2002 23:11:39 -0000 1.2 +++ ClassGeneratorTest.cs 7 Oct 2002 00:08:02 -0000 1.3 @@ -27,6 +27,23 @@ string AProperty { get; set; } } + public abstract class SolidThingy + { + public virtual string VirtualMethod() { return "xx"; } + public override string ToString() { return "xx"; } + public abstract string AbstractMethod(); + + // cannot override + public static string StaticMethod() { return "xx"; } + public string NonVirtualMethod() { return "xx"; } + private string privateMethod() { return "xx"; } + internal string internalMethod() { return "xx"; } + protected virtual string protectedMethod() { return "xx"; } + protected internal virtual string protectedInternalMethod() { return "xx"; } + string defaultInternalMethod() { return "xx"; } + + } + [TestFixture] public class ClassGeneratorTest { @@ -201,6 +218,25 @@ mock.Verify(); } + [Test] + public void ExtendClass() + { + cg = new ClassGenerator(); + SolidThingy s = (SolidThingy)cg.Generate(typeof(SolidThingy), mock); + + mock.ExpectAndReturn("VirtualMethod", "hello"); + mock.ExpectAndReturn("ToString", "STRING"); + mock.ExpectAndReturn("GetHashCode", 123); + mock.ExpectAndReturn("AbstractMethod", "fish"); + Assertion.AssertEquals("hello", s.VirtualMethod()); + Assertion.AssertEquals("STRING", s.ToString()); + Assertion.AssertEquals(123, s.GetHashCode()); + Assertion.AssertEquals("fish", s.AbstractMethod()); + + Assertion.AssertEquals("xx", s.NonVirtualMethod()); + mock.Verify(); + } + [Test] public void BoxingOpCodes() { |