public void SupportsTransparentProxyAsTarget() { AppDomain domain = null; try { domain = AppDomain.CreateDomain("Spring"); 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); } }
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 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."); } }