public void CanMixTransparentProxyAndVirtualMethodInterceptors() { IUnityContainer container = GetConfiguredContainer("CanMixTransparentProxyAndVirtualMethodInterceptors"); container .Configure <Interception>() .AddPolicy("policy") .AddMatchingRule <AlwaysMatchingRule>() .AddCallHandler <CallCountHandler>(); Wrappable anonymousWrappable = container.Resolve <Wrappable>(); Wrappable namedWrappable = container.Resolve <Wrappable>("name"); WrappableWithVirtualMethods anonymousWrappableWrappableWithVirtualMethods = container.Resolve <WrappableWithVirtualMethods>(); WrappableWithVirtualMethods namedWrappableWrappableWithVirtualMethods = container.Resolve <WrappableWithVirtualMethods>("name"); Assert.IsTrue(RemotingServices.IsTransparentProxy(anonymousWrappable)); Assert.IsTrue(RemotingServices.IsTransparentProxy(namedWrappable)); Assert.AreSame( typeof(WrappableWithVirtualMethods), anonymousWrappableWrappableWithVirtualMethods.GetType()); Assert.AreSame( typeof(WrappableWithVirtualMethods), namedWrappableWrappableWithVirtualMethods.GetType().BaseType); }
public void CanSetUpAPolicyWithNonGenericInjectedRulesAndHandlers() { IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); container .Configure <Interception>() .AddPolicy("policy1") .AddMatchingRule(typeof(AlwaysMatchingRule)) .AddCallHandler( typeof(GlobalCountCallHandler), new InjectionConstructor("handler1")) .AddCallHandler( typeof(GlobalCountCallHandler), new InjectionConstructor("handler2"), new InjectionProperty("Order", 10)); GlobalCountCallHandler.Calls.Clear(); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new TransparentProxyInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]); }
public void CanSetUpAPolicyWithLifetimeManagedInjectedRulesAndHandlers() { IUnityContainer container = GetConfiguredContainer("CanSetUpAPolicyWithLifetimeManagedInjectedRulesAndHandlers"); GlobalCountCallHandler.Calls.Clear(); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new TransparentProxyInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]); Assert.AreSame( container.Resolve <IMatchingRule>("rule1"), container.Resolve <IMatchingRule>("rule1")); Assert.AreNotSame( container.Resolve <IMatchingRule>("rule2"), container.Resolve <IMatchingRule>("rule2")); Assert.AreSame( container.Resolve <ICallHandler>("handler1"), container.Resolve <ICallHandler>("handler1")); Assert.AreNotSame( container.Resolve <ICallHandler>("handler2"), container.Resolve <ICallHandler>("handler2")); }
public void CanSetUpAPolicyWithLifetimeManagedNamedInjectedRulesAndHandlers() { IUnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container .Configure<Interception>() .AddPolicy("foo") .AddMatchingRule<AlwaysMatchingRule>( "rule1", new ContainerControlledLifetimeManager()) .AddCallHandler<CallCountHandler>( "handler1", (LifetimeManager)null) .AddCallHandler<CallCountHandler>( "handler2", new ContainerControlledLifetimeManager(), new InjectionProperty("Order", 10)); GlobalCountCallHandler.Calls.Clear(); container .Configure<Interception>() .SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor()); Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable"); wrappable1.Method2(); CallCountHandler handler1 = (CallCountHandler)container.Resolve<ICallHandler>("handler1"); CallCountHandler handler2 = (CallCountHandler)container.Resolve<ICallHandler>("handler2"); Assert.AreEqual(0, handler1.CallCount); // not lifetime maanaged Assert.AreEqual(1, handler2.CallCount); // lifetime managed }
public void CanSetUpAPolicyWithExternallyConfiguredRulesAndHandlers() { IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); container .Configure <Interception>() .AddPolicy("policy1") .AddMatchingRule("rule1") .AddCallHandler("handler1") .AddCallHandler("handler2").Interception.Container .RegisterType <IMatchingRule, AlwaysMatchingRule>("rule1") .RegisterType <ICallHandler, GlobalCountCallHandler>( "handler1", new InjectionConstructor("handler1")) .RegisterType <ICallHandler, GlobalCountCallHandler>( "handler2", new InjectionConstructor("handler2"), new InjectionProperty("Order", 10)); GlobalCountCallHandler.Calls.Clear(); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new VirtualMethodInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]); }
public void CanSetUpAPolicyWithGivenRulesAndHandlers() { IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); IMatchingRule rule1 = new AlwaysMatchingRule(); ICallHandler handler1 = new CallCountHandler(); container .Configure <Interception>() .AddPolicy("policy1") .AddMatchingRule(rule1) .AddCallHandler(handler1); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new VirtualMethodInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, ((CallCountHandler)handler1).CallCount); }
public void WillNotCreateWrappedObjectIfNoInterceptionPolicyIsSpecified() { IUnityContainer container = CreateContainer("CanCreateWrappedObject"); Wrappable wrappable = container.Resolve <Wrappable>(); Assert.IsNotNull(wrappable); Assert.IsFalse(RemotingServices.IsTransparentProxy(wrappable)); }
public void CanCreateWrappedObjectIfDefaultInterceptionPolicy() { IUnityContainer container = CreateContainer("CanCreateWrappedObject"); container.Configure <Interception>().SetDefaultInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Wrappable wrappable = container.Resolve <Wrappable>(); Assert.IsNotNull(wrappable); Assert.IsTrue(RemotingServices.IsTransparentProxy(wrappable)); }
public void CanInterceptWrappedObject() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanCreateWrappedObject"); container.Configure <Interception>().SetInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Wrappable wrappable = container.Resolve <Wrappable>(); wrappable.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]); }
public void CanInterceptExistingWrappedObject() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanCreateWrappedObject") .RegisterType <Wrappable>( new Interceptor <TransparentProxyInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>()); Wrappable wrappable = container.BuildUp <Wrappable>(new Wrappable()); wrappable.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]); }
public void CanConfigureInterceptorForTypeAndName() { IUnityContainer container = GetConfiguredContainer("CanConfigureInterceptorForTypeAndName"); container .Configure <Interception>() .AddPolicy("policy") .AddMatchingRule <AlwaysMatchingRule>() .AddCallHandler <CallCountHandler>(); Wrappable anonymous = container.Resolve <Wrappable>(); Wrappable named = container.Resolve <Wrappable>("name"); Assert.IsFalse(RemotingServices.IsTransparentProxy(anonymous)); Assert.IsTrue(RemotingServices.IsTransparentProxy(named)); }
public void CanSetUpAPolicyWithGivenRulesAndHandlersTypes() { IUnityContainer container = GetConfiguredContainer("CanSetUpAPolicyWithGivenRulesAndHandlersTypes"); GlobalCountCallHandler.Calls.Clear(); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new TransparentProxyInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["default"]); }
public void CanInterceptWrappedObjectWithValueTypeRef() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanInterceptWrappedObjectWithValueTypeRef"); container.Configure <Interception>().SetInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Wrappable wrappable = container.Resolve <Wrappable>(); int someObj = 0; wrappable.MethodRefValue(ref someObj); Assert.AreEqual(42, someObj); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptWrappedObjectWithValueTypeRef"]); }
public void CanInterceptWrappedObjectWithRef() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanInterceptWrappedObjectWithRef"); container.Configure <Interception>().SetInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Wrappable wrappable = container.Resolve <Wrappable>(); object foo = null; wrappable.MethodRef(ref foo); Assert.AreEqual("foo", foo); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptWrappedObjectWithRef"]); }
public void CanInterceptWrappedObject() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanCreateWrappedObject"); container.RegisterType <Wrappable>( new Interceptor <VirtualMethodInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>()); Wrappable wrappable = container.Resolve <Wrappable>(); wrappable.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanCreateWrappedObject"]); }
public void CanInterceptCallsToMBROOverInterface() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanInterceptCallsToMBROOverInterface"); container .Configure <Interception>() .SetInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Wrappable wrappable = container.Resolve <Wrappable>(); ((Interface)wrappable).Method(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptCallsToMBROOverInterface"]); }
public void CanInterceptWrappedObjectWithValueTypeRef() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanInterceptWrappedObjectWithValueTypeRef"); container.RegisterType <Wrappable>( new Interceptor <VirtualMethodInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>()); Wrappable wrappable = container.Resolve <Wrappable>(); int someObj = 0; wrappable.MethodRefValue(ref someObj); Assert.AreEqual(42, someObj); Assert.AreEqual(1, GlobalCountCallHandler.Calls["CanInterceptWrappedObjectWithValueTypeRef"]); }
public void CanInterceptCallsToLifetimeManagedMappedMBROOverInterface() { GlobalCountCallHandler.Calls.Clear(); IUnityContainer container = CreateContainer("CanInterceptCallsToMappedMBROOverInterface"); container .RegisterType <Interface, Wrappable>(new ContainerControlledLifetimeManager()) .Configure <Interception>() .SetInterceptorFor <Wrappable>(new TransparentProxyInterceptor()); Interface wrappable = container.Resolve <Interface>(); wrappable.Method(); Wrappable wrappable2 = container.Resolve <Wrappable>(); wrappable2.Method(); Assert.AreEqual(2, GlobalCountCallHandler.Calls["CanInterceptCallsToMappedMBROOverInterface"]); }
public void CanMixDefaultAndNonDefaultInterceptors() { IUnityContainer container = GetConfiguredContainer("CanMixDefaultAndNonDefaultInterceptors"); container .Configure <Interception>() .AddPolicy("policy") .AddMatchingRule <AlwaysMatchingRule>() .AddCallHandler <CallCountHandler>(); Wrappable anonymousWrappable = container.Resolve <Wrappable>(); Wrappable namedWrappable = container.Resolve <Wrappable>("name"); WrappableWithProperty anonymousWrappableWithProperty = container.Resolve <WrappableWithProperty>(); WrappableWithProperty namedWrappableWithProperty = container.Resolve <WrappableWithProperty>("name"); Assert.IsTrue(RemotingServices.IsTransparentProxy(anonymousWrappable)); Assert.IsTrue(RemotingServices.IsTransparentProxy(namedWrappable)); Assert.IsTrue(RemotingServices.IsTransparentProxy(anonymousWrappableWithProperty)); Assert.IsFalse(RemotingServices.IsTransparentProxy(namedWrappableWithProperty)); }
public void CanSetUpAPolicyWithGivenRulesAndHandlersTypesWithGenerics() { IUnityContainer container = new UnityContainer(); container.AddNewExtension<Interception>(); container .Configure<Interception>() .AddPolicy("foo") .AddMatchingRule<AlwaysMatchingRule>() .AddCallHandler<GlobalCountCallHandler>(); GlobalCountCallHandler.Calls.Clear(); container .Configure<Interception>() .SetInterceptorFor<Wrappable>("wrappable", new TransparentProxyInterceptor()); Wrappable wrappable1 = container.Resolve<Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["default"]); }
public void CanSetUpAPolicyWithLifetimeManagedInjectedRulesAndHandlers() { IUnityContainer container = this.GetConfiguredContainer("policyWithLifetimeManagedInjectedRulesAndHandlers"); GlobalCountCallHandler.Calls.Clear(); container .RegisterType <Wrappable>("wrappable", new Interceptor <TransparentProxyInterceptor>(), new InterceptionBehavior <PolicyInjectionBehavior>()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler1"]); Assert.AreEqual(1, GlobalCountCallHandler.Calls["handler2"]); var matchingRuleRegistrations = container.Registrations.Where(r => r.RegisteredType == typeof(IMatchingRule)); var callHandlerRegistrations = container.Registrations.Where(r => r.RegisteredType == typeof(ICallHandler)); Assert.AreEqual(2, matchingRuleRegistrations.Count()); Assert.AreEqual( 1, matchingRuleRegistrations.Where(r => r.LifetimeManagerType == typeof(ContainerControlledLifetimeManager)).Count()); Assert.AreEqual( 1, matchingRuleRegistrations.Where(r => r.LifetimeManagerType == typeof(TransientLifetimeManager)).Count()); Assert.AreEqual(2, callHandlerRegistrations.Count()); Assert.AreEqual( 1, callHandlerRegistrations.Where(r => r.LifetimeManagerType == typeof(ContainerControlledLifetimeManager)).Count()); Assert.AreEqual( 1, callHandlerRegistrations.Where(r => r.LifetimeManagerType == typeof(TransientLifetimeManager)).Count()); }
public void CanSetUpAPolicyWithGivenRulesAndHandlersTypes() { IUnityContainer container = new UnityContainer(); container.AddNewExtension <Interception>(); container .Configure <Interception>() .AddPolicy("policy1") .AddMatchingRule(typeof(AlwaysMatchingRule)) .AddCallHandler(typeof(GlobalCountCallHandler)); GlobalCountCallHandler.Calls.Clear(); container .Configure <Interception>() .SetInterceptorFor <Wrappable>("wrappable", new VirtualMethodInterceptor()); Wrappable wrappable1 = container.Resolve <Wrappable>("wrappable"); wrappable1.Method2(); Assert.AreEqual(1, GlobalCountCallHandler.Calls["default"]); }
public Wrappable(Collider2D col) { this.col = col; this.clone = null; this.escaping = false; }