Пример #1
0
        public void MethodInjectorCanCallGenericMethod()
        {
            MethodInfo gtd    = typeof(ObjectWithGenericMethod).GetMethod("ConvertGeneric");
            MethodInfo method = gtd.MakeGenericMethod(typeof(int));

            IMethodInjector injector = Factory.GetInjector(method);

            Assert.That(injector, Is.Not.Null);

            ObjectWithGenericMethod obj = new ObjectWithGenericMethod();
            string result = injector.Invoke(obj, new object[] { 42 }) as string;

            Assert.That(result, Is.EqualTo("42"));
        }
Пример #2
0
        public void CanInterceptGenericMethodOnInterface()
        {
            var interceptor = new CallCountInterceptionBehavior();

            var original    = new ObjectWithGenericMethod();
            var intercepted = new InterceptingRealProxy(original, typeof(IInterfaceWithGenericMethod))
                              .GetTransparentProxy() as IInterfaceWithGenericMethod;

            IInterceptingProxy proxy = (IInterceptingProxy)intercepted;

            proxy.AddInterceptionBehavior(interceptor);

            var result = intercepted.GetTypeName(6);

            Assert.AreEqual("Int32", result);
            Assert.AreEqual(1, interceptor.CallCount);
        }