private object CreateDynamicProxy <TActorInterface>(object target, IActorProxy actorProxy) where TActorInterface : IActor { var generator = new ProxyGenerator(new PersistentProxyBuilder()); var selector = new InterceptorSelector(); var actorInterceptor = new ActorInterceptor(PreActorMethod, PostActorMethod); var actorProxyInterceptor = new ActorProxyInterceptor(actorProxy); var options = new ProxyGenerationOptions() { Selector = selector }; var proxy = generator.CreateInterfaceProxyWithTarget(typeof(TActorInterface), new Type[] { typeof(IActorProxy) }, target, options, actorInterceptor, actorProxyInterceptor); return(proxy); }
public void DisposesLifetimeScopeWhenTriggerMethodInvoked() { var lifetimeScope = new Mock <ILifetimeScope>(MockBehavior.Strict); lifetimeScope.Setup(x => x.Dispose()).Verifiable(); var invocation = new Mock <IInvocation>(MockBehavior.Strict); invocation.Setup(x => x.Proceed()).Verifiable(); invocation.Setup(x => x.Method.Name).Returns("OnDeactivateAsync").Verifiable(); var interceptor = new ActorInterceptor(lifetimeScope.Object); interceptor.Intercept(invocation.Object); lifetimeScope.Verify(); invocation.Verify(); }