コード例 #1
0
        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());
        }
コード例 #2
0
        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())));
        }
コード例 #3
0
        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())));
        }
コード例 #4
0
        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())));
        }
コード例 #5
0
        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())));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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()));
        }
コード例 #8
0
        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())));
        }
コード例 #9
0
        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())));
        }
コード例 #10
0
        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()));
        }
コード例 #11
0
        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()));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
 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));
 }