public void SelectInterceptors_returns_SelectorInterceptor_for_properties_marked_with_Selector_attribute() { var subject = new InterceptorSelector(); var interceptors = new IInterceptor[] { new SelectorInterceptor(), new XPathInterceptor() }; // PageObject var methodInfo = typeof(FakePageObject).GetProperty(nameof(FakePageObject.SelectorForElementHandle)).GetMethod; var result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); methodInfo = typeof(FakePageObject).GetProperty(nameof(FakePageObject.SelectorForElementHandleArray)).GetMethod; result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); methodInfo = typeof(FakePageObject).GetProperty(nameof(FakePageObject.SelectorForElementObject)).GetMethod; result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); // ElementObject methodInfo = typeof(FakeElementObject).GetProperty(nameof(FakeElementObject.SelectorForElementHandle)).GetMethod; result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); methodInfo = typeof(FakeElementObject).GetProperty(nameof(FakeElementObject.SelectorForElementHandleArray)).GetMethod; result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); methodInfo = typeof(FakeElementObject).GetProperty(nameof(FakeElementObject.SelectorForElementObject)).GetMethod; result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.IsType <SelectorInterceptor>(result.Single()); }
public void SelectInterceptors_returns_other_interceptors_for_properties_not_marked_with_Selector_or_XPath_attribute() { var subject = new InterceptorSelector(); var interceptors = new IInterceptor[] { new SelectorInterceptor(), new XPathInterceptor(), new StandardInterceptor() }; var methodInfo = typeof(string).GetMethod(nameof(string.GetTypeCode)); var result = subject.SelectInterceptors(null, methodInfo, interceptors); Assert.Same(interceptors.Last(), result.Single()); }
public void When_using_CreateInterfaceProxyWithoutTarget_SelectInterceptors_receives_type_equal_to_null() { var selector = new InterceptorSelector(); var proxy = generator.CreateInterfaceProxyWithoutTarget <IFoo>(new ProxyGenerationOptions { Selector = selector }, new DoNothingInterceptor()); proxy.Method(); Assert.AreEqual(null, selector.ReceivedType); }
public void When_using_CreateClassProxyWithTarget_SelectInterceptors_receives_type_equal_to_type_of_target() { var selector = new InterceptorSelector(); var proxy = generator.CreateClassProxyWithTarget <Foo>(new FooTarget(), new ProxyGenerationOptions { Selector = selector }, new DoNothingInterceptor()); proxy.Method(); Assert.AreEqual(typeof(FooTarget), selector.ReceivedType); }
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); }