Exemplo n.º 1
0
        public void Add_TypeList()
        {
            var list = new ServiceInterceptorList();

            list.GetInterceptors(typeof(IProxiedService)).ShouldBeEmpty();
            Should.Throw <ArgumentNullException>(() => list.Add(typeof(IProxiedService), (Type)null));
            Should.Throw <ArgumentNullException>(() => list.Add(null, (ITypeList <IInterceptor>)null));
            Should.Throw <ArgumentNullException>(() => list.Add(null, new TypeList <IInterceptor>()));
            list.Add(typeof(IProxiedService), new TypeList <IInterceptor>());
            list.GetInterceptors(typeof(IProxiedService)).ShouldBeEmpty();
            list.Add(typeof(IProxiedService), new TypeList <IInterceptor>().Action(l => l.Add <TestInterceptor>()));
            list.GetInterceptors(typeof(IProxiedService)).ShouldHaveSingleItem().ShouldBe(typeof(TestInterceptor));
        }
Exemplo n.º 2
0
        public void EnablePropertyInjection()
        {
            var build        = new ContainerBuilder().RegisterType <PropertyInjectionService>();
            var interceptors = new ServiceInterceptorList();

            interceptors.Add(typeof(TestProxiedService), typeof(TestInterceptor));
            var container = Substitute.For <IModuleContainer>();
            var module    = Substitute.For <IModuleDescriptor>();

            module.Configure().Assembly.Returns(typeof(PropertyInjectionService).Assembly);
            container.Configure().Modules.Returns(new List <IModuleDescriptor> {
                module
            });
            Should.NotThrow(() => build.ConfigureConventions(container, interceptors));
            build.RegistrationData.ActivatingHandlers.ShouldHaveSingleItem();
        }
Exemplo n.º 3
0
        public void InvokeRegistrationActions()
        {
            var build        = new ContainerBuilder().RegisterType <TestProxiedService>();
            var interceptors = new ServiceInterceptorList();

            interceptors.Add(typeof(TestProxiedService), typeof(TestInterceptor));
            var container = Substitute.For <IModuleContainer>();

            Should.NotThrow(() => build.ConfigureConventions(container, interceptors));
            build.RegistrationData.Metadata.Where(kv => kv.Key == "Autofac.Extras.DynamicProxy.RegistrationExtensions.InterceptorsPropertyName").ShouldHaveSingleItem().Action(kv =>
            {
                kv.Key.ShouldBe("Autofac.Extras.DynamicProxy.RegistrationExtensions.InterceptorsPropertyName");
                kv.Value.As <IEnumerable <Service> >().ShouldHaveSingleItem().ShouldBeOfType <TypedService>().ServiceType.ShouldBe(typeof(AsyncDeterminationInterceptor <TestInterceptor>));
            }
                                                                                                                                                                               );
            build = new ContainerBuilder().RegisterType <TestProxiedService>().As <IProxiedService>();
            Should.NotThrow(() => build.ConfigureConventions(container, interceptors));
            build.RegistrationData.Metadata.Where(kv => kv.Key == "Autofac.Extras.DynamicProxy.RegistrationExtensions.InterceptorsPropertyName").ShouldHaveSingleItem().Action(kv =>
            {
                kv.Key.ShouldBe("Autofac.Extras.DynamicProxy.RegistrationExtensions.InterceptorsPropertyName");
                kv.Value.As <IEnumerable <Service> >().ShouldHaveSingleItem().ShouldBeOfType <TypedService>().ServiceType.ShouldBe(typeof(AsyncDeterminationInterceptor <TestInterceptor>));
            }
                                                                                                                                                                               );
        }