protected override void Initialize() { base.Context.Strategies.AddNew <AutoInstanceInterceptionStrategy>(UnityBuildStage.Setup); base.Context.Strategies.AddNew <AutoTypeInterceptionStrategy>(UnityBuildStage.PreCreation); TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor(); this.Container.RegisterInstance <IInterceptor>(typeof(IInterceptor).AssemblyQualifiedName, interceptor, new ContainerControlledLifetimeManager()); }
public void CanCreateProxyWithAdditionalInterfaces() { IInstanceInterceptor interceptor = new TransparentProxyInterceptor(); SingleInterceptableMethod target = new SingleInterceptableMethod(); object proxy = interceptor.CreateProxy(typeof(SingleInterceptableMethod), target, typeof(IMyOperations)); Assert.IsTrue(proxy is IMyOperations); }
public void Given() { var container = new UnityContainer(); interceptor = new TransparentProxyInterceptor(); var injectionMember = new InstanceInterceptionPolicySettingInjectionMember(interceptor); assertingInjectionMember = new PolicyExposingInjectionMember(); container.RegisterType <Foo>(injectionMember, assertingInjectionMember); }
public void AssortedParameterKindsAreProperlyHandled() { var interceptor = new TransparentProxyInterceptor(); var target = new AssortedParameterKindsAreProperlyHandledHelper.TypeWithAssertedParameterKinds(); IInterceptingProxy proxy = interceptor.CreateProxy( typeof(AssortedParameterKindsAreProperlyHandledHelper.TypeWithAssertedParameterKinds), target); AssortedParameterKindsAreProperlyHandledHelper.PerformTest(proxy); }
static void TransparentProxyInterceptor(object instance) { //Transparent proxy interceptor var interceptor = new TransparentProxyInterceptor(); var canIntercept = interceptor.CanIntercept(instance); var myProxy = interceptor.Intercept(instance, typeof(IMyType), new MyHandler()) as IMyType; var proxy = myProxy as IInterceptionProxy; var otherInterceptor = proxy.Interceptor; var result = myProxy.MyMethod(); Assert.AreEqual(20, result); }
public void HandlersCanChangeInputsBeforeTargetIsCalled() { TransparentProxyInterceptor factory = new TransparentProxyInterceptor(); PolicySet policies = GetPolicies(); CanChangeParametersTarget target = new CanChangeParametersTarget(); IInterceptingProxy proxy = factory.CreateProxy(typeof(CanChangeParametersTarget), target); ApplyPolicies(factory, proxy, target, policies); CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy; Assert.AreEqual(0, intercepted.MostRecentInput); intercepted.DoSomething(2); Assert.AreEqual(4, intercepted.MostRecentInput); }
SignatureTestTarget GetTarget() { TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor(); PolicySet policySet = GetPolicies(); SignatureTestTarget target = new SignatureTestTarget(); IInterceptingProxy proxy = interceptor.CreateProxy(typeof(SignatureTestTarget), target); foreach (MethodImplementationInfo method in interceptor.GetInterceptableMethods(typeof(SignatureTestTarget), typeof(SignatureTestTarget))) { HandlerPipeline pipeline = new HandlerPipeline( policySet.GetHandlersFor(method, container)); proxy.SetPipeline(method.ImplementationMethodInfo, pipeline); } return((SignatureTestTarget)proxy); }
public void HandlersCanChangeRefsAfterTargetReturns() { TransparentProxyInterceptor factory = new TransparentProxyInterceptor(); PolicySet policies = GetPolicies(); CanChangeParametersTarget target = new CanChangeParametersTarget(); IInterceptingProxy proxy = factory.CreateProxy(typeof(CanChangeParametersTarget), target); ApplyPolicies(factory, proxy, target, policies); CanChangeParametersTarget intercepted = (CanChangeParametersTarget)proxy; int output = 3; intercepted.DoSomethingElseWithRef(2, ref output); Assert.AreEqual((2 + 3 + 5) * 3, output); }
SignatureTestTarget GetTarget() { TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor(); PolicySet policySet = GetPolicies(); SignatureTestTarget target = new SignatureTestTarget(); IInterceptingProxy proxy = interceptor.CreateProxy(typeof(SignatureTestTarget), target); PipelineManager manager = new PipelineManager(); foreach (MethodImplementationInfo method in interceptor.GetInterceptableMethods(typeof(SignatureTestTarget), typeof(SignatureTestTarget))) { HandlerPipeline pipeline = new HandlerPipeline( policySet.GetHandlersFor(method, container)); manager.SetPipeline(method.ImplementationMethodInfo, pipeline); } proxy.AddInterceptionBehavior(new PolicyInjectionBehavior(manager)); return (SignatureTestTarget)proxy; }
private static List <MethodImplementationInfo> GetMethods <T>() { TransparentProxyInterceptor interceptor = new TransparentProxyInterceptor(); return(new List <MethodImplementationInfo>(interceptor.GetInterceptableMethods(typeof(T), typeof(T)))); }