Exemplo n.º 1
0
        public void Throw_Method()
        {
            var generator   = new ProxyGenerator();
            var interceptor = new IntForIC1();
            var target      = new TypeIC1();
            var proxy       = generator.CreateClassProxyWithTarget <TypeIC1>(target, interceptor);

            target.Throw      = true;
            interceptor.Throw = true;

            Assert.AreEqual(0, interceptor.States.Count);

            bool isThrown = false;

            try
            {
                proxy.Method1();
            }
            catch (Exception)
            {
                isThrown = true;
            }

            Assert.IsTrue(isThrown);
            Assert.IsTrue(target.IsCalled);
            Assert.AreEqual(2, interceptor.States.Count);
            Assert.AreEqual(StateTypes.Enter_Interceptor, interceptor.States[0]);
            Assert.AreEqual(StateTypes.Exception_Interceptor, interceptor.States[1]);
            Assert.AreEqual("Method", interceptor.Ex.Message);
        }
Exemplo n.º 2
0
        public void CancelAfter()
        {
            var generator   = new ProxyGenerator();
            var interceptor = new IntForIC1();
            var target      = new TypeIC1();
            var proxy       = generator.CreateClassProxyWithTarget <TypeIC1>(target, interceptor);

            interceptor.ThrowAfter = true;

            Assert.AreEqual(0, interceptor.States.Count);

            proxy.Method1();

            Assert.AreEqual(3, interceptor.States.Count);
            Assert.AreEqual(StateTypes.Enter_Interceptor, interceptor.States[0]);
            Assert.AreEqual(StateTypes.Exit_Interceptor, interceptor.States[1]);
            Assert.AreEqual(StateTypes.Exception_Interceptor, interceptor.States[2]);
            Assert.AreEqual("After", interceptor.Ex.Message);
        }