public override object BuildUp(IBuilderContext context, object buildKey, object existing) { Type typeToBuild; if (TryGetTypeFromBuildKey(buildKey, out typeToBuild)) { Type originalType; if (!TryGetTypeFromBuildKey(context.OriginalBuildKey, out originalType)) { originalType = typeToBuild; } IObjectFactory factory = context.Locator.Get <IObjectFactory>(); if (factory != null) { InterceptionReflector.Reflect(originalType, typeToBuild, context.Policies, factory); } } return(base.BuildUp(context, buildKey, existing)); }
public void ClassWithNoDecorations() { PolicyList policies = new PolicyList(); InterceptionReflector.Reflect <object>(policies, new StubObjectFactory()); Assert.Equal(0, policies.Count); }
public void RequestingToBuildNonInterfaceMeansMethodsNotIntercepted() { PolicyList policies = new PolicyList(); InterceptionReflector.Reflect <OneMethod>(policies, new StubObjectFactory()); Assert.Equal(0, policies.Count); }
public void NonPublicInterfaceNotCompatible() { PolicyList policies = new PolicyList(); Assert.Throws <InvalidOperationException>( delegate { InterceptionReflector.Reflect <INonPublicInterface, NonPublicInterface>(policies, new StubObjectFactory()); }); }
public void VirtualSealedMethodNotCompatible() { PolicyList policies = new PolicyList(); Assert.Throws <InvalidOperationException>( delegate { InterceptionReflector.Reflect <VirtualSealed>(policies, new StubObjectFactory()); }); }
public void SealedTypeNotCompatible() { PolicyList policies = new PolicyList(); Assert.Throws <InvalidOperationException>( delegate { InterceptionReflector.Reflect <SealedClass>(policies, new StubObjectFactory()); }); }
public void NonMBROTypeIncompatibleWithRemoting() { PolicyList policies = new PolicyList(); Assert.Throws <InvalidOperationException>( delegate { InterceptionReflector.Reflect <NonMBRO>(policies, new StubObjectFactory()); }); }
public void CanMixInterceptionTypes() { PolicyList policies = new PolicyList(); InterceptionReflector.Reflect <IFoo, FooBar>(policies, new StubObjectFactory()); Assert.Equal(1, policies.Get <IVirtualInterceptionPolicy>(typeof(FooBar)).Count); Assert.Equal(1, policies.Get <IInterfaceInterceptionPolicy>(typeof(FooBar)).Count); Assert.Equal(1, policies.Get <IRemotingInterceptionPolicy>(typeof(FooBar)).Count); }
public void OneInterceptedMethod() { PolicyList policies = new PolicyList(); MethodBase method = typeof(IOneMethod).GetMethod("InterceptedMethod"); InterceptionReflector.Reflect <IOneMethod, OneMethod>(policies, new StubObjectFactory()); IInterfaceInterceptionPolicy policy = policies.Get <IInterfaceInterceptionPolicy>(typeof(OneMethod)); Assert.Equal(1, policy.Count); Assert.Equal(1, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); }
public void ReflectShouldHappenOnGenericBaseClass() { PolicyList policies = new PolicyList(); MethodBase method = typeof(Generic <>).GetMethod("DoSomething"); InterceptionReflector.Reflect <Generic <int> >(policies, new StubObjectFactory()); IVirtualInterceptionPolicy policy = policies.Get <IVirtualInterceptionPolicy>(typeof(Generic <>)); Assert.Equal(1, policy.Count); Assert.Equal(1, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); }
public void InterceptionIsInherited() { PolicyList policies = new PolicyList(); MethodBase method = typeof(DerivedOneMethod).GetMethod("InterceptedMethod"); InterceptionReflector.Reflect <DerivedOneMethod>(policies, new StubObjectFactory()); IRemotingInterceptionPolicy policy = policies.Get <IRemotingInterceptionPolicy>(typeof(DerivedOneMethod)); Assert.Equal(1, policy.Count); Assert.Equal(1, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); }
public void RequestingToBuildInterface1WillNotInterceptedInterface2Methods() { PolicyList policies = new PolicyList(); MethodBase method = typeof(IInterface1).GetMethod("InterceptedMethod1"); InterceptionReflector.Reflect <IInterface1, TwoInterfaceClass>(policies, new StubObjectFactory()); IInterfaceInterceptionPolicy policy = policies.Get <IInterfaceInterceptionPolicy>(typeof(TwoInterfaceClass)); Assert.Equal(1, policy.Count); Assert.Equal(1, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); }
public void CanAddHandlersInInheritedClass() { PolicyList policies = new PolicyList(); MethodBase method = typeof(IOneMethod).GetMethod("InterceptedMethod"); InterceptionReflector.Reflect <IOneMethod, DerivedWithAddedIntercepts>(policies, new StubObjectFactory()); IInterfaceInterceptionPolicy policy = policies.Get <IInterfaceInterceptionPolicy>(typeof(DerivedWithAddedIntercepts)); Assert.Equal(1, policy.Count); Assert.Equal(2, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); Assert.IsType <RecordingHandler>(policy[method][1]); }
public void TwoAttributesOnOneMethod() { PolicyList policies = new PolicyList(); MethodBase method = typeof(OneMethodTwoAttributes).GetMethod("InterceptedMethod"); InterceptionReflector.Reflect <OneMethodTwoAttributes>(policies, new StubObjectFactory()); IVirtualInterceptionPolicy policy = policies.Get <IVirtualInterceptionPolicy>(typeof(OneMethodTwoAttributes)); Assert.Equal(1, policy.Count); Assert.Equal(2, policy[method].Count); Assert.IsType <RecordingHandler>(policy[method][0]); Assert.IsType <RecordingHandler>(policy[method][1]); }
public void TwoInterceptedMethods() { PolicyList policies = new PolicyList(); MethodBase method1 = typeof(TwoMethods).GetMethod("InterceptedMethod1"); MethodBase method2 = typeof(TwoMethods).GetMethod("InterceptedMethod2"); InterceptionReflector.Reflect <TwoMethods>(policies, new StubObjectFactory()); IVirtualInterceptionPolicy policy = policies.Get <IVirtualInterceptionPolicy>(typeof(TwoMethods)); Assert.Equal(2, policy.Count); Assert.Equal(1, policy[method1].Count); Assert.IsType <RecordingHandler>(policy[method1][0]); Assert.Equal(1, policy[method2].Count); Assert.IsType <RecordingHandler>(policy[method2][0]); }