Example #1
0
        [Test] public void DoesNotOverrideToString()
        {
            cg = new ClassGenerator(typeof(AbstractThingy), mock);
            AbstractThingy s = (AbstractThingy)cg.Generate();

            mock.SetupResult("ToString", "to string");

            Assertion.AssertEquals("xx", s.ToString());
            mock.Verify();
        }
Example #2
0
        // Limitations
        [Test] public void CannotOverrideNonVirtualFeatures()
        {
            cg = new ClassGenerator(typeof(AbstractThingy), mock);
            AbstractThingy s = (AbstractThingy)cg.Generate();

            mock.SetupResult("NonVirtualMethod", "non virtual method");
            mock.SetupResult("NonVirtualProperty", "non virtual property");

            Assertion.AssertEquals("xx", s.NonVirtualMethod());
            Assertion.AssertEquals("xx", s.NonVirtualProperty);
            mock.Verify();
        }
Example #3
0
        [Test] public void CreateGenericProxy()
        {
            InvocationHandlerImpl handler = new InvocationHandlerImpl();
            ClassGenerator        cg      = new ClassGenerator(typeof(IThingy), handler);
            IThingy thingy = (IThingy)cg.Generate();

            handler.expectedMethodName = "NoArgs";

            thingy.NoArgs();

            Assertion.Assert("Should have been called ", handler.wasCalled);
        }
Example #4
0
        [Test] public void CanExtendAbstractClass()
        {
            cg = new ClassGenerator(typeof(AbstractThingy), mock);
            AbstractThingy s = (AbstractThingy)cg.Generate();

            mock.ExpectAndReturn("VirtualMethod", "hello");
            mock.ExpectAndReturn("GetHashCode", 123);
            mock.ExpectAndReturn("AbstractMethod", "fish");
            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();
        }
Example #5
0
        public void CanExtendDerivedClass()
        {
            cg = new ClassGenerator(typeof(RealThingy), mock);
            RealThingy s = (RealThingy)cg.Generate();

            mock.ExpectAndReturn("VirtualMethod", "hello");
            mock.ExpectAndReturn("GetHashCode", 123);
            mock.ExpectAndReturn("AbstractMethod", "fish");
            mock.ExpectAndReturn("ProtectedInternalMethod", "white");
            mock.ExpectAndReturn("OtherProperty", "abc");

            Assertion.AssertEquals("hello", s.VirtualMethod());
            Assertion.AssertEquals(123, s.GetHashCode());
            Assertion.AssertEquals("fish", s.AbstractMethod());
            Assertion.AssertEquals("white", s.ProtectedInternalMethod());
            Assertion.AssertEquals("abc", s.OtherProperty);

            mock.Verify();
        }
Example #6
0
		[Test] public void DoesNotOverrideToString()
		{
			cg = new ClassGenerator(typeof(AbstractThingy), mock);
			AbstractThingy s = (AbstractThingy)cg.Generate();

			mock.SetupResult("ToString", "to string");

			Assertion.AssertEquals("xx", s.ToString());
			mock.Verify();
		}
Example #7
0
		// Limitations
		[Test] public void CannotOverrideNonVirtualFeatures()
		{
			cg = new ClassGenerator(typeof(AbstractThingy), mock);
			AbstractThingy s = (AbstractThingy)cg.Generate();

			mock.SetupResult("NonVirtualMethod", "non virtual method");
			mock.SetupResult("NonVirtualProperty", "non virtual property");

			Assertion.AssertEquals("xx", s.NonVirtualMethod());
			Assertion.AssertEquals("xx", s.NonVirtualProperty);
			mock.Verify();
		}
Example #8
0
		public void CanExtendDerivedClass()
		{
			cg = new ClassGenerator(typeof(RealThingy), mock);
			RealThingy s = (RealThingy)cg.Generate();

			mock.ExpectAndReturn("VirtualMethod", "hello");
			mock.ExpectAndReturn("GetHashCode", 123);
			mock.ExpectAndReturn("AbstractMethod", "fish");
			mock.ExpectAndReturn("ProtectedInternalMethod", "white");
			mock.ExpectAndReturn("OtherProperty", "abc");

			Assertion.AssertEquals("hello", s.VirtualMethod());
			Assertion.AssertEquals(123, s.GetHashCode());
			Assertion.AssertEquals("fish", s.AbstractMethod());
			Assertion.AssertEquals("white", s.ProtectedInternalMethod());
			Assertion.AssertEquals("abc", s.OtherProperty);

			mock.Verify();
		}
Example #9
0
		[Test] public void CanExtendAbstractClass()
		{
			cg = new ClassGenerator(typeof(AbstractThingy), mock);
			AbstractThingy s = (AbstractThingy)cg.Generate();

			mock.ExpectAndReturn("VirtualMethod", "hello");
			mock.ExpectAndReturn("GetHashCode", 123);
			mock.ExpectAndReturn("AbstractMethod", "fish");
			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();
		}
Example #10
0
		[SetUp] public void SetUp()
		{
			mock = new Mock("Test Mock");
			cg = new ClassGenerator(typeof(IThingy), mock);
			thingy = (IThingy)cg.Generate();
		}
Example #11
0
		[Test] public void CreateGenericProxy()
		{
			InvocationHandlerImpl handler = new InvocationHandlerImpl();
			ClassGenerator cg = new ClassGenerator(typeof(IThingy), handler);
			IThingy thingy = (IThingy)cg.Generate();

			handler.expectedMethodName = "NoArgs";

			thingy.NoArgs();

			Assertion.Assert("Should have been called ", handler.wasCalled);
		}
Example #12
0
 [SetUp] public void SetUp()
 {
     mock   = new Mock("Test Mock");
     cg     = new ClassGenerator(typeof(IThingy), mock);
     thingy = (IThingy)cg.Generate();
 }