Exemplo n.º 1
0
        public void TestIntroductionInterceptorWithSuperInterface()
        {
            TestObject raw = new TestObject();

            Assert.IsTrue(!(raw is ITimeStamped));
            ProxyFactory factory = new ProxyFactory(raw);

            ISubTimeStampedIntroduction ts = A.Fake <ISubTimeStampedIntroduction>();

            A.CallTo(() => ts.TimeStamp).Returns(EXPECTED_TIMESTAMP);

            factory.AddIntroduction(0, new DefaultIntroductionAdvisor(
                                        ts,
                                        typeof(ITimeStamped))
                                    );

            ITimeStamped tsp = (ITimeStamped)factory.GetProxy();

            Assert.IsTrue(!(tsp is ISubTimeStamped));
            Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
        }
        public void TestIntroductionInterceptorWithInterfaceHierarchy()
        {
            TestObject raw = new TestObject();

            Assert.IsTrue(!(raw is ISubTimeStamped));
            ProxyFactory factory = new ProxyFactory(raw);

            ISubTimeStampedIntroduction ts = MockRepository.GenerateMock <ISubTimeStampedIntroduction>();

            ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);

            DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);

            // we must add introduction, not an advisor
            factory.AddIntroduction(advisor);

            object          proxy = factory.GetProxy();
            ISubTimeStamped tsp   = (ISubTimeStamped)proxy;

            Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
        }
        public void testIntroductionInterceptorWithInterfaceHierarchy()
        {
            TestObject raw = new TestObject();

            Assert.IsTrue(!(raw is ISubTimeStamped));
            ProxyFactory factory = new ProxyFactory(raw);

            IDynamicMock tsControl         = new DynamicMock(typeof(ISubTimeStampedIntroduction));
            ISubTimeStampedIntroduction ts = (ISubTimeStampedIntroduction)tsControl.Object;

            tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);

            DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);

            // we must add introduction, not an advisor
            factory.AddIntroduction(advisor);

            object          proxy = factory.GetProxy();
            ISubTimeStamped tsp   = (ISubTimeStamped)proxy;

            Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);

            tsControl.Verify();
        }