public void AttachedHandlersAreCalled() { CallCountHandler h1 = new CallCountHandler(); CallCountHandler h2 = new CallCountHandler(); IUnityContainer container = GetConfiguredContainer(h1, h2); AddPoliciesToContainer(container); ConfigureInterceptionWithRegisterType(container); Interceptee foo = container.Resolve <Interceptee>(); int oneCount = 0; int twoCount = 0; for (oneCount = 0; oneCount < 2; ++oneCount) { foo.MethodOne(); } for (twoCount = 0; twoCount < 3; ++twoCount) { foo.MethodTwo("hi", twoCount); } Assert.AreEqual(oneCount, h1.CallCount); Assert.AreEqual(twoCount, h2.CallCount); }
public void InterceptedClassGetsReturned() { CallCountHandler h1 = new CallCountHandler(); CallCountHandler h2 = new CallCountHandler(); IUnityContainer container = GetConfiguredContainer(h1, h2); AddPoliciesToContainer(container); ConfigureInterceptionWithRegisterType(container); Interceptee target = container.Resolve <Interceptee>(); Assert.AreNotSame(typeof(Interceptee), target.GetType()); }
public void AttachedHandlersAreCalled() { CallCountHandler h1 = new CallCountHandler(); CallCountHandler h2 = new CallCountHandler(); IUnityContainer container = new UnityContainer() .AddNewExtension <Interception>() .RegisterInstance <ICallHandler>("h1", h1) .RegisterInstance <ICallHandler>("h2", h2) .RegisterType <Interceptee>( new Interceptor <VirtualMethodInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>()) .Configure <Interception>() .AddPolicy("methodOne") .AddMatchingRule <MemberNameMatchingRule>(new InjectionConstructor("MethodOne")) .AddCallHandler("h1") .Interception .AddPolicy("methodTwo") .AddMatchingRule <MemberNameMatchingRule>(new InjectionConstructor("MethodTwo")) .AddCallHandler("h2") .Interception.Container; Interceptee target = container.Resolve <Interceptee>(); int oneCount = 0; int twoCount = 0; for (oneCount = 0; oneCount < 2; ++oneCount) { target.MethodOne(); } for (twoCount = 0; twoCount < 3; ++twoCount) { target.MethodTwo("hi", twoCount); } Assert.AreEqual(oneCount, h1.CallCount); Assert.AreEqual(twoCount, h2.CallCount); }