private void CallGetObject() { ProxyFactoryObject proxyFactory = (ProxyFactoryObject)this.factory.GetObject("&concurrentPrototype"); ITestObject prevTestObject = null; for (int i = 0; i < 20; i++) { ITestObject o = proxyFactory.GetObject() as ITestObject; Assert.IsNotNull(o); Assert.AreNotSame(prevTestObject, o); prevTestObject = o; Thread.Sleep(0); } }
public void NullNameInInterceptorNamesArrayThrowAopConfigException() { IObjectFactory factory = (IObjectFactory)mocks.CreateMock(typeof(IObjectFactory)); ProxyFactoryObject fac = new ProxyFactoryObject(); fac.ProxyInterfaces = new string[] { typeof(ICommand).FullName }; fac.IsSingleton = false; fac.InterceptorNames = new string[] { null, null }; fac.ObjectFactory = factory; try { fac.GetObject(); Assert.Fail(); } catch (AopConfigException) {} }
public void GlobalsCanAddAspectInterfaces() { IAddedGlobalInterface agi = (IAddedGlobalInterface)factory.GetObject("autoInvoker"); Assert.IsTrue(agi.GlobalsAdded == -1); ProxyFactoryObject pfb = (ProxyFactoryObject)factory.GetObject("&validGlobals"); pfb.GetObject(); // for creation Assert.AreEqual(2, pfb.Advisors.Count, "Proxy should have 1 global and 1 explicit advisor"); Assert.AreEqual(1, pfb.Introductions.Count, "Proxy should have 1 global introduction"); agi.GlobalsAdded = ((IAdvised)agi).Introductions.Count; Assert.IsTrue(agi.GlobalsAdded == 1); IApplicationEventListener l = (IApplicationEventListener)factory.GetObject("validGlobals"); agi = (IAddedGlobalInterface)l; Assert.IsTrue(agi.GlobalsAdded == -1); Assert.Throws <InvalidCastException>(() => factory.GetObject <IAddedGlobalInterface>("test1")); }
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."); } }