public void ProxyTransparentProxy() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); ConstructorArgumentValues ctorArgs = new ConstructorArgumentValues(); ctorArgs.AddNamedArgumentValue("objectType", typeof(ITestObject)); of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(TransparentProxyFactory), ctorArgs, null)); TestAutoProxyCreator apc = new TestAutoProxyCreator(of); of.AddObjectPostProcessor(apc); ITestObject o = of.GetObject("bar") as ITestObject; Assert.IsTrue(AopUtils.IsAopProxy(o)); // ensure interceptors get called o.Foo(); Assert.AreEqual(1, apc.NopInterceptor.Count); IAdvised advised = (IAdvised)o; // ensure target was called object target = advised.TargetSource.GetTarget(); Assert.AreEqual(1, TransparentProxyFactory.GetRealProxy(target).Count); }
public void ProxyObjectWithoutInterface() { DefaultListableObjectFactory of = new DefaultListableObjectFactory(); of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(ObjectWithoutInterface))); TestAutoProxyCreator apc = new TestAutoProxyCreator(of); of.AddObjectPostProcessor(apc); ObjectWithoutInterface o = of.GetObject("bar") as ObjectWithoutInterface; Assert.IsTrue(AopUtils.IsAopProxy(o)); o.Foo(); Assert.AreEqual(1, apc.NopInterceptor.Count); }