public void ConfigureOption_Add_Test() { IAspectConfigureOption <object> ConfigureOption = new AspectConfigure().GetConfigureOption <object>(); Func <MethodInfo, object> option = m => new object(); ConfigureOption.Add(option); Assert.Single(ConfigureOption, option); }
public void IgnoreOption_Test() { var Configure = new AspectConfigure(); var ignoreOption = Configure.GetConfigureOption <bool>(); Assert.NotNull(ignoreOption); Assert.NotEmpty(ignoreOption); }
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 With_Type_Interceptor_Test() { var Configure = new AspectConfigure(); var matcher = new InterceptorMatcher(Configure); var method = ReflectionExtensions.GetMethod <Action <WithInterceptorMatcherModel> >(m => m.WithOutInterceptor()); var interceptors = matcher.Match(method, typeof(WithInterceptorMatcherModel).GetTypeInfo()); Assert.NotEmpty(interceptors); Assert.Single(interceptors); }
public void WithOutInterceptor_Test() { var Configure = new AspectConfigure(); var matcher = new InterceptorMatcher(Configure); var method = ReflectionExtensions.GetMethod <Action <InterceptorMatcherModel> >(m => m.WithOutInterceptor()); var interceptors = matcher.Match(method, method.DeclaringType.GetTypeInfo()); Assert.Empty(interceptors); }
public void UseOption_Test() { var Configure = new AspectConfigure(); var userOption = Configure.GetConfigureOption <IInterceptor>(); Assert.NotNull(userOption); Assert.Empty(userOption); Func <MethodInfo, IInterceptor> defaultOption = m => default(IInterceptor); userOption.Add(defaultOption); Assert.Contains(defaultOption, userOption); }
public void Inject_NoFromServicesAttribute_Test() { var Configure = new AspectConfigure(); var interceptor = new InjectedInterceptor(); Assert.Null(interceptor.ConfigureWithNoFromServicesAttribute); var interceptorInjector = new InterceptorInjector(new InstanceServiceProvider(new OriginalServiceProvider(Configure)), new PropertyInjectorSelector().SelectPropertyInjector(typeof(InjectedInterceptor))); interceptorInjector.Inject(interceptor); Assert.Null(interceptor.ConfigureWithNoFromServicesAttribute); }
public void Inject_NoSetAccessor_Test() { var Configure = new AspectConfigure(); var interceptor = new InjectedInterceptor(); Assert.Null(interceptor.ConfigureWithNoSet); var interceptorInjector = new InterceptorInjector(new InstanceServiceProvider(Configure), new PropertyInjectorSelector().SelectPropertyInjector(typeof(InjectedInterceptor))); interceptorInjector.Inject(interceptor); Assert.Null(interceptor.ConfigureWithNoSet); }
public void With_Configure_Interceptor_Test() { var Configure = new AspectConfigure(); var ConfigureInterceptor = new InjectedInterceptor(); Configure.GetConfigureOption <IInterceptor>().Add(m => ConfigureInterceptor); var matcher = new InterceptorMatcher(Configure); var method = ReflectionExtensions.GetMethod <Action <InterceptorMatcherModel> >(m => m.ConfigureInterceptor()); var interceptors = matcher.Match(method, method.DeclaringType.GetTypeInfo()); Assert.NotEmpty(interceptors); Assert.Single(interceptors, ConfigureInterceptor); }
public static IServiceCollection AddAspectConfigure(this IServiceCollection services, Action <IAspectConfigure> configure) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var aspectConfigure = new AspectConfigure(); configure.Invoke(aspectConfigure); services.AddSingleton <IAspectConfigure>(aspectConfigure); return(services); }
public void InvokeA_Test() { var Configure = new AspectConfigure(); var serviceProvider = new InstanceServiceProvider(null); var activator = new AspectActivator(serviceProvider, new AspectBuilderProvider(new InterceptorSelector(new InterceptorMatcher(Configure), new InterceptorInjectorProvider(serviceProvider, new PropertyInjectorSelector())))); var input = 0; var activatorContext = Substitute.For <AspectActivatorContext>(); activatorContext.Parameters.Returns(new object[] { input }); activatorContext.ServiceType.Returns(typeof(ITargetService)); activatorContext.ServiceMethod.Returns(ReflectionExtensions.GetMethod <Func <ITargetService, int, int> >((m, v) => m.Add(v))); activatorContext.TargetMethod.Returns(ReflectionExtensions.GetMethod <Func <TargetService, int, int> >((m, v) => m.Add(v))); activatorContext.ProxyMethod.Returns(ReflectionExtensions.GetMethod <Func <ProxyService, int, int> >((m, v) => m.Add(v))); activatorContext.TargetInstance.Returns(new TargetService()); activatorContext.ProxyInstance.Returns(new ProxyService()); var result = activator.Invoke <int>(activatorContext); Assert.Equal(result, input + 1); }