Inheritance: IProxyGenerationHook
Ejemplo n.º 1
0
        public void Hook_can_see_GetHashCode_method()
        {
            var hook = new LogHook(typeof(EmptyClass));

            generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

            var getHashCode = typeof(EmptyClass).GetMethod("GetHashCode");

            CollectionAssert.Contains(hook.AskedMembers, getHashCode);
        }
Ejemplo n.º 2
0
        public void Hook_can_see_ToString_method()
        {
            var hook = new LogHook(typeof(EmptyClass));

            generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

            var equals = typeof(EmptyClass).GetMethod("ToString");

            CollectionAssert.Contains(hook.AskedMembers, equals);
        }
Ejemplo n.º 3
0
		public void Hook_can_NOT_see_GetType_method()
		{
			var hook = new LogHook(typeof(EmptyClass));

			generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

			var getType = typeof(EmptyClass).GetMethod("GetType");
			CollectionAssert.DoesNotContain(hook.AskedMembers, getType);
			CollectionAssert.DoesNotContain(hook.NonVirtualMembers, getType);
		}
Ejemplo n.º 4
0
        public void Hook_can_NOT_see_MemberwiseClone_method()
        {
            var hook = new LogHook(typeof(EmptyClass));

            generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

            var memberwiseClone = typeof(EmptyClass).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);

            CollectionAssert.DoesNotContain(hook.AskedMembers, memberwiseClone);
            CollectionAssert.DoesNotContain(hook.NonVirtualMembers, memberwiseClone);
        }
Ejemplo n.º 5
0
        public void Hook_can_NOT_see_GetType_method()
        {
            var hook = new LogHook(typeof(EmptyClass));

            generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

            var getType = typeof(EmptyClass).GetMethod("GetType");

            CollectionAssert.DoesNotContain(hook.AskedMembers, getType);
            CollectionAssert.DoesNotContain(hook.NonVirtualMembers, getType);
        }
Ejemplo n.º 6
0
        public void HookIsUsedForConcreteClassProxy()
        {
            var logger = new LogInvocationInterceptor();
            var hook   = new LogHook(typeof(ServiceClass), true);

            var options = new ProxyGenerationOptions(hook);

            var proxy = (ServiceClass)generator.CreateClassProxy(typeof(ServiceClass), options, logger);

            Assert.IsTrue(hook.Completed);
            Assert.AreEqual(13, hook.AskedMembers.Count, "Asked members");
            Assert.AreEqual(2, hook.NonVirtualMembers.Count, "Non-virtual members");

            proxy.Sum(1, 2);
            Assert.IsFalse(proxy.Valid);

            Assert.AreEqual("get_Valid ", logger.LogContents);
        }
Ejemplo n.º 7
0
		public void HookIsUsedForConcreteClassProxy()
		{
			var logger = new LogInvocationInterceptor();
			var hook = new LogHook(typeof(ServiceClass), true);

			var options = new ProxyGenerationOptions(hook);

			var proxy = (ServiceClass)generator.CreateClassProxy(typeof(ServiceClass), options, logger);

			Assert.IsTrue(hook.Completed);
			Assert.AreEqual(13, hook.AskedMembers.Count, "Asked members");
			Assert.AreEqual(2, hook.NonVirtualMembers.Count, "Non-virtual members");

			proxy.Sum(1, 2);
			Assert.IsFalse(proxy.Valid);

			Assert.AreEqual("get_Valid ", logger.LogContents);
		}
Ejemplo n.º 8
0
        public void HookIsUsedForInterfaceProxy()
        {
            var logger = new LogInvocationInterceptor();
            var hook   = new LogHook(typeof(IService), false);

            var options = new ProxyGenerationOptions(hook);

            var proxy = (IService)
                        generator.CreateInterfaceProxyWithTarget(
                typeof(IService), new ServiceImpl(), options, logger);

            Assert.IsTrue(hook.Completed);
            Assert.AreEqual(10, hook.AskedMembers.Count);
            Assert.AreEqual(0, hook.NonVirtualMembers.Count);

            Assert.AreEqual(3, proxy.Sum(1, 2));
            Assert.IsFalse(proxy.Valid);

            Assert.AreEqual("Sum get_Valid ", logger.LogContents);
        }
Ejemplo n.º 9
0
        public void HookDetectsNonVirtualAlthoughInterfaceImplementation()
        {
            var logger = new LogInvocationInterceptor();
            var hook   = new LogHook(typeof(ServiceImpl), true);

            var options = new ProxyGenerationOptions(hook);

            // we are creating a class proxy although the creation of an interface proxy is possible too...
            // since the members of our implementation are not explicitly marked as virtual, the runtime
            // marks them as virtual but final --> not good for us, but intended by .net :-(
            //
            // see: https://msdn.microsoft.com/library/system.reflection.methodbase.isvirtual
            //
            // thus, a non virtual notification for this particular situation is appropriate
            generator.CreateClassProxy(typeof(ServiceImpl), options, logger);

            Assert.IsTrue(hook.Completed);
            Assert.AreEqual(3, hook.AskedMembers.Count);
            Assert.AreEqual(11, hook.NonVirtualMembers.Count);
        }
Ejemplo n.º 10
0
		public void HookIsUsedForInterfaceProxy()
		{
			var logger = new LogInvocationInterceptor();
			var hook = new LogHook(typeof(IService), false);

			var options = new ProxyGenerationOptions(hook);

			var proxy = (IService)
			            generator.CreateInterfaceProxyWithTarget(
			            	typeof(IService), new ServiceImpl(), options, logger);

			Assert.IsTrue(hook.Completed);
			Assert.AreEqual(10, hook.AskedMembers.Count);
			Assert.AreEqual(0, hook.NonVirtualMembers.Count);

			Assert.AreEqual(3, proxy.Sum(1, 2));
			Assert.IsFalse(proxy.Valid);

			Assert.AreEqual("Sum get_Valid ", logger.LogContents);
		}
Ejemplo n.º 11
0
		public void Hook_can_see_Equals_method()
		{
			var hook = new LogHook(typeof(EmptyClass));

			generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

			var equals = typeof(EmptyClass).GetMethod("Equals");
			CollectionAssert.Contains(hook.AskedMembers, equals);
		}
Ejemplo n.º 12
0
		public void Hook_can_NOT_see_MemberwiseClone_method()
		{
			var hook = new LogHook(typeof(EmptyClass));

			generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

			var memberwiseClone = typeof(EmptyClass).GetMethod("MemberwiseClone", BindingFlags.NonPublic | BindingFlags.Instance);
			CollectionAssert.DoesNotContain(hook.AskedMembers, memberwiseClone);
			CollectionAssert.DoesNotContain(hook.NonVirtualMembers, memberwiseClone);
		}
Ejemplo n.º 13
0
		public void Hook_can_see_GetHashCode_method()
		{
			var hook = new LogHook(typeof(EmptyClass));

			generator.CreateClassProxy(typeof(EmptyClass), new ProxyGenerationOptions(hook));

			var getHashCode = typeof(EmptyClass).GetMethod("GetHashCode");
			CollectionAssert.Contains(hook.AskedMembers, getHashCode);
		}