예제 #1
0
        public void SupportsTransparentProxyAsTarget()
        {
            AppDomain domain = null;

            try
            {
                AppDomainSetup setup = new AppDomainSetup();
                setup.ApplicationBase = Environment.CurrentDirectory;
                domain = AppDomain.CreateDomain("Spring", new Evidence(AppDomain.CurrentDomain.Evidence), setup);
                object command = domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(RemotableCommand).FullName);

                ProxyFactoryObject fac = new ProxyFactoryObject();
                fac.AddInterface(typeof(ICommand));
                fac.AddAdvice(new NopInterceptor());
                fac.Target = command;

                IAdvised advised = fac.GetObject() as IAdvised;
                Assert.IsNotNull(advised);

                ICommand cmd = fac.GetObject() as ICommand;
                Assert.IsNotNull(cmd);

                cmd.Execute();
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }
예제 #2
0
        private ProxyFactoryObject CreateFrozenProxyFactory()
        {
            ProxyFactoryObject fac = new ProxyFactoryObject();

            fac.AddInterface(typeof(ITestObject));
            fac.IsFrozen = true;
            fac.AddAdvisor(new PointcutForVoid()); // this is ok, no proxy created yet
            fac.GetObject();
            return(fac);
        }
예제 #3
0
        public void ProxiedObjectUnwrapsTargetInvocationException()
        {
            ProxyFactoryObject fac = new ProxyFactoryObject();

            fac.AddInterface(typeof(ICommand));
            fac.AddAdvice(new NopInterceptor());
            fac.Target = new BadCommand();

            ICommand cmd = (ICommand)fac.GetObject();

            try
            {
                cmd.Execute();
            }
            catch (NotImplementedException)
            {
                // this is good, we want this exception to bubble up...
            }
            catch (TargetInvocationException)
            {
                Assert.Fail("Must have unwrapped this.");
            }
        }
 private ProxyFactoryObject CreateFrozenProxyFactory()
 {
     ProxyFactoryObject fac = new ProxyFactoryObject();
     fac.AddInterface(typeof(ITestObject));
     fac.IsFrozen = true;
     fac.AddAdvisor(new PointcutForVoid()); // this is ok, no proxy created yet
     fac.GetObject();
     return fac;
 }
        public void SupportsTransparentProxyAsTarget()
        {
            AppDomain domain = null;
            try
            {
                AppDomainSetup setup = new AppDomainSetup();
                setup.ApplicationBase = Environment.CurrentDirectory;
                domain = AppDomain.CreateDomain("Spring", new Evidence(AppDomain.CurrentDomain.Evidence), setup);
                object command = domain.CreateInstanceAndUnwrap(GetType().Assembly.FullName, typeof(RemotableCommand).FullName);

                ProxyFactoryObject fac = new ProxyFactoryObject();
                fac.AddInterface(typeof(ICommand));
                fac.AddAdvice(new NopInterceptor());
                fac.Target = command;

                IAdvised advised = fac.GetObject() as IAdvised;
                Assert.IsNotNull(advised);

                ICommand cmd = fac.GetObject() as ICommand;
                Assert.IsNotNull(cmd);

                cmd.Execute();
            }
            finally
            {
                AppDomain.Unload(domain);
            }
        }
        public void ProxiedObjectUnwrapsTargetInvocationException()
        {
            ProxyFactoryObject fac = new ProxyFactoryObject();
            fac.AddInterface(typeof(ICommand));
            fac.AddAdvice(new NopInterceptor());
            fac.Target = new BadCommand();

            ICommand cmd = (ICommand)fac.GetObject();
            try
            {
                cmd.Execute();
            }
            catch (NotImplementedException)
            {
                // this is good, we want this exception to bubble up...
            }
            catch (TargetInvocationException)
            {
                Assert.Fail("Must have unwrapped this.");
            }
        }