public void Equals_DifferentOptions_Hook() { IProxyGenerationHook hook = new LogHook(typeof(object), true); _options1.Hook = hook; Assert.AreNotEqual(_options1, _options2); }
public void GetHashCode_DifferentOptions_Hook() { IProxyGenerationHook hook = new LogHook(typeof(object), true); _options1.Hook = hook; Assert.AreNotEqual(_options1.GetHashCode(), _options2.GetHashCode()); }
public void Hook_does_NOT_get_notified_about_autoproperty_field() { var hook = new LogHook(typeof(VirtualClassWithAutoProperty), false); generator.CreateClassProxyWithTarget(typeof(VirtualClassWithAutoProperty), Type.EmptyTypes, new VirtualClassWithAutoProperty(), new ProxyGenerationOptions(hook), new object[0]); Assert.False(hook.NonVirtualMembers.Any(m => m is FieldInfo)); }
public void Hook_does_NOT_get_notified_about_autoproperty_field() { var hook = new LogHook(typeof(VirtualClassWithAutoProperty), false); generator.CreateClassProxyWithTarget(typeof(VirtualClassWithAutoProperty), Type.EmptyTypes, new VirtualClassWithAutoProperty(), new ProxyGenerationOptions(hook), new object[0]); Assert.False(hook.NonVirtualMembers.Any(m => m is FieldInfo)); }
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); }
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); }
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); }
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); }
public void Hook_gets_notified_about_static_methods() { var hook = new LogHook(typeof(VirtualClassWithPublicField), false); generator.CreateClassProxyWithTarget(typeof(VirtualClassWithPublicField), Type.EmptyTypes, new VirtualClassWithPublicField(), new ProxyGenerationOptions(hook), new object[0]); Assert.IsNotEmpty((ICollection)hook.NonVirtualMembers); var memberInfo = hook.NonVirtualMembers.Single(m => m is FieldInfo); Assert.AreEqual("field", memberInfo.Name); Assert.AreEqual(MemberTypes.Field, memberInfo.MemberType); }
public void Hook_gets_notified_about_static_methods() { var hook = new LogHook(typeof(VirtualClassWithPublicField), false); generator.CreateClassProxyWithTarget(typeof(VirtualClassWithPublicField), Type.EmptyTypes, new VirtualClassWithPublicField(), new ProxyGenerationOptions(hook), new object[0]); Assert.IsNotEmpty((ICollection)hook.NonVirtualMembers); var memberInfo = hook.NonVirtualMembers.Single(m => m is FieldInfo); Assert.AreEqual("field", memberInfo.Name); }
public void Hook_gets_notified_about_public_field() { var hook = new LogHook(typeof(VirtualClassWithPublicField), false); generator.CreateClassProxyWithTarget(typeof(VirtualClassWithPublicField), Type.EmptyTypes, new VirtualClassWithPublicField(), new ProxyGenerationOptions(hook), new object[0]); Assert.IsNotEmpty((ICollection)hook.NonVirtualMembers); var memberInfo = hook.NonVirtualMembers.Single(m => m is FieldInfo); Assert.AreEqual("field", memberInfo.Name); #if FEATURE_LEGACY_REFLECTION_API Assert.AreEqual(MemberTypes.Field, memberInfo.MemberType); #endif }
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); }
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(4, hook.NonVirtualMembers.Count, "Non-virtual members"); proxy.Sum(1, 2); Assert.IsFalse(proxy.Valid); Assert.AreEqual("get_Valid ", logger.LogContents); }
public void HookIsUsedForConcreteClassProxy() { LogInvocationInterceptor logger = new LogInvocationInterceptor(); LogHook hook = new LogHook(typeof (ServiceClass), true); ProxyGenerationOptions options = new ProxyGenerationOptions(hook); ServiceClass proxy = (ServiceClass) generator.CreateClassProxy(typeof (ServiceClass), options, logger); Assert.IsTrue(hook.Completed); Assert.AreEqual(10, hook.AskedMembers.Count, "Asked members"); Assert.AreEqual(2, hook.NonVirtualMembers.Count, "Non-virtual members");// <-- this would fail due to superfulous method check proxy.Sum(1, 2); Assert.IsFalse(proxy.Valid); Assert.AreEqual("get_Valid ", logger.LogContents); }
public void HookIsUsedForConcreteClassProxy() { LogInvocationInterceptor logger = new LogInvocationInterceptor(); LogHook hook = new LogHook(typeof(ServiceClass), true); ProxyGenerationOptions options = new ProxyGenerationOptions(hook); ServiceClass proxy = (ServiceClass)generator.CreateClassProxy(typeof(ServiceClass), options, logger); Assert.IsTrue(hook.Completed); Assert.AreEqual(10, hook.AskedMembers.Count, "Asked members"); Assert.AreEqual(2, hook.NonVirtualMembers.Count, "Non-virtual members"); // <-- this would fail due to superfulous method check proxy.Sum(1, 2); Assert.IsFalse(proxy.Valid); Assert.AreEqual("get_Valid ", logger.LogContents); }
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); }
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); }
public void HookIsUsedForInterfaceProxy() { LogInvocationInterceptor logger = new LogInvocationInterceptor(); LogHook hook = new LogHook(typeof (IService), false); ProxyGenerationOptions options = new ProxyGenerationOptions(hook); IService 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); }
public void Equals_DifferentOptions_Hook() { IProxyGenerationHook hook = new LogHook(typeof(object), true); _options1.Hook = hook; Assert.AreNotEqual(_options1, _options2); }
public void GetHashCode_DifferentOptions_Hook() { IProxyGenerationHook hook = new LogHook(typeof (object), true); _options1.Hook = hook; Assert.AreNotEqual(_options1.GetHashCode(), _options2.GetHashCode()); }