public void Dynamically_TestWithClass() { var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); var proxyType = generator.CreateClassProxyType(typeof(AbsTargetService), typeof(TargetService)); Assert.True(proxyType.GetTypeInfo().IsProxyType()); }
public void ValidateInterceptor_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.True(validator.Validate(ReflectionExtensions.GetMethod <Action <ClassWithInterceptorValidatorModel> >(m => m.Validate()))); Assert.True(validator.Validate(ReflectionExtensions.GetMethod <Action <MethodWithInterceptorValidatorModel> >(m => m.Validate()))); }
public void ValidateNonAspect_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <ClassNonAspectValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <MethodNonAspectValidatorModel> >(m => m.Validate()))); }
public void ValidateDeclaringMethod_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <FinalMethodValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <NonPublicMethodValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action>(() => StaticMethodValidatorModel.Validate()))); }
public void ValidateDeclaringType_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <NotPublicValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <VauleTypeValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <SealedValidatorModel> >(m => m.Validate()))); }
public void CreateProxyType_Test() { var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); var proxyType = generator.CreateInterfaceProxyType(typeof(ITargetService), typeof(TargetService)); var proxyInstance = Activator.CreateInstance(proxyType, new InstanceServiceProvider(null), new InstanceServiceProvider(new TargetService())); Assert.IsAssignableFrom <ITargetService>(proxyInstance); }
public void ValidateInterceptor_Type_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.True(validator.Validate(typeof(ClassWithInterceptorValidatorModel))); Assert.True(validator.Validate(typeof(MethodWithInterceptorValidatorModel))); Assert.True(validator.Validate(typeof(ClassWithInterceptorValidatorModel).GetTypeInfo())); Assert.True(validator.Validate(typeof(MethodWithInterceptorValidatorModel).GetTypeInfo())); }
public void Configure_ValidateInterceptor_Test() { var configure = new AspectConfigure(); configure.GetConfigureOption <IInterceptor>().Add(m => new IncrementAttribute()); var validator = AspectValidatorFactory.GetAspectValidator(configure); Assert.True(validator.Validate(ReflectionExtensions.GetMethod <Action <ConfigureInterceptorValidatorModel> >(m => m.Validate()))); }
public void ValidateIgnoredList_Test() { var configure = new AspectConfigure(); configure.GetConfigureOption <bool>().Add(m => m.DeclaringType.Name.Matches("IgnoredList*")); var validator = AspectValidatorFactory.GetAspectValidator(configure); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <IgnoredListValidatorModel> >(m => m.Validate()))); Assert.False(validator.Validate(ReflectionExtensions.GetMethod <Action <object> >(m => m.ToString()))); }
public void ValidateDeclaringMethod_Type_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.False(validator.Validate(typeof(FinalMethodValidatorModel))); Assert.False(validator.Validate(typeof(NonPublicMethodValidatorModel))); Assert.False(validator.Validate(typeof(StaticMethodValidatorModel))); Assert.False(validator.Validate(typeof(FinalMethodValidatorModel).GetTypeInfo())); Assert.False(validator.Validate(typeof(NonPublicMethodValidatorModel).GetTypeInfo())); Assert.False(validator.Validate(typeof(StaticMethodValidatorModel).GetTypeInfo())); }
public void ValidateDeclaringType_Type_Test() { var validator = AspectValidatorFactory.GetAspectValidator(new AspectConfigure()); Assert.False(validator.Validate(typeof(NotPublicValidatorModel))); Assert.False(validator.Validate(typeof(VauleTypeValidatorModel))); Assert.False(validator.Validate(typeof(SealedValidatorModel))); Assert.False(validator.Validate(typeof(NotPublicValidatorModel).GetTypeInfo())); Assert.False(validator.Validate(typeof(VauleTypeValidatorModel).GetTypeInfo())); Assert.False(validator.Validate(typeof(SealedValidatorModel).GetTypeInfo())); }
public void get_ServiceInstance_With_Generic_Test() { var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); var proxyType = generator.CreateInterfaceProxyType(typeof(ITargetService), typeof(TargetService)); var serviceInsatnce = new TargetService(); var proxyInstance = Activator.CreateInstance(proxyType, new InstanceServiceProvider(null), new InstanceServiceProvider(serviceInsatnce)); var serviceInstanceAccessor = proxyInstance as IServiceInstanceAccessor <ITargetService>; Assert.NotNull(serviceInstanceAccessor); Assert.Equal <ITargetService>(serviceInstanceAccessor.ServiceInstance, serviceInsatnce); }
public void Create_Generic_ProxyType_Test() { var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); var proxyType = generator.CreateInterfaceProxyType(typeof(ITargetService <>), typeof(TargetService <>)); Assert.True(proxyType.GetTypeInfo().IsGenericTypeDefinition); Assert.Single(proxyType.GetTypeInfo().GenericTypeParameters); var proxyInstance = Activator.CreateInstance(proxyType.MakeGenericType(typeof(object)), new InstanceServiceProvider(null), new InstanceServiceProvider(null)); Assert.IsAssignableFrom <ITargetService <object> >(proxyInstance); }
public void CreateProxyType_Cache_Test() { var generator = new ProxyGenerator(AspectValidatorFactory.GetAspectValidator(new AspectConfigure())); var proxyType = generator.CreateInterfaceProxyType(typeof(ITargetService), typeof(TargetService)); var proxyTypeCache = generator.CreateInterfaceProxyType(typeof(ITargetService), typeof(TargetService)); }