public void SelectorWorksForGenericMethods()
        {
            var options             = new ProxyGenerationOptions();
            var countingInterceptor = new CallCountingInterceptor();

            options.Selector = new TypeInterceptorSelector <CallCountingInterceptor>();
            var target =
                generator.CreateInterfaceProxyWithTarget(
                    typeof(IGenericInterface),
                    new GenericClass(),
                    options,
                    new AddTwoInterceptor(),
                    countingInterceptor
                    ) as IGenericInterface;

            Assert.IsNotNull(target);
            var result = target.GenericMethod <int>();

            Assert.AreEqual(1, countingInterceptor.Count);
            Assert.AreEqual(0, result);
            var result2 = target.GenericMethod <string>();

            Assert.AreEqual(2, countingInterceptor.Count);
            Assert.AreEqual(default(string), result2);
        }
Example #2
0
        public void SelectorWorksForMethods()
        {
            var options             = new ProxyGenerationOptions();
            var countingInterceptor = new CallCountingInterceptor();

            options.Selector = new TypeInterceptorSelector <CallCountingInterceptor>();
            var target = generator.CreateInterfaceProxyWithTarget(typeof(ISimpleInterface), new SimpleClass(), options,
                                                                  new AddTwoInterceptor(), countingInterceptor) as ISimpleInterface;

            Assert.IsNotNull(target);
            var result = target.Do();

            Assert.AreEqual(3, result);
            Assert.AreEqual(1, countingInterceptor.Count);
        }
Example #3
0
        public void SelectorWorksForProperties()
        {
            ProxyGenerationOptions  options             = new ProxyGenerationOptions();
            CallCountingInterceptor countingInterceptor = new CallCountingInterceptor();

            options.Selector = new TypeInterceptorSelector <CallCountingInterceptor>();
            ISimpleInterfaceWithProperty target =
                generator.CreateInterfaceProxyWithTarget(typeof(ISimpleInterfaceWithProperty),
                                                         new SimpleClassWithProperty(), options,
                                                         new AddTwoInterceptor(),
                                                         countingInterceptor) as ISimpleInterfaceWithProperty;

            Assert.IsNotNull(target);
            int result = target.Age;

            Assert.AreEqual(5, result);
            Assert.AreEqual(1, countingInterceptor.Count);
        }
Example #4
0
        public void SelectorWorksForMultipleGenericMethods()
        {
            ProxyGenerationOptions  options             = new ProxyGenerationOptions();
            CallCountingInterceptor countingInterceptor = new CallCountingInterceptor();

            options.Selector = new TypeInterceptorSelector <CallCountingInterceptor>();
            IMultiGenericInterface target =
                generator.CreateInterfaceProxyWithTarget(typeof(IMultiGenericInterface), new MultiGenericClass(),
                                                         options,
                                                         new AddTwoInterceptor(),
                                                         countingInterceptor) as IMultiGenericInterface;

            Assert.IsNotNull(target);
            int result = target.Method <int, string>("ignored");

            Assert.AreEqual(1, countingInterceptor.Count);
            Assert.AreEqual(0, result);
            string result2 = target.Method <string, int>(0);

            Assert.AreEqual(2, countingInterceptor.Count);
            Assert.AreEqual(default(string), result2);
        }