Пример #1
0
        public void System_interfaces_should_not_be_auto_registered()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.ConfigureComponent(typeof(ComponentWithSystemInterface),
                                                   DependencyLifecycle.InstancePerCall);

            Assert.False(configureComponents.HasComponent(typeof(IGrouping <string, string>)));
            Assert.False(configureComponents.HasComponent(typeof(IDisposable)));
        }
Пример #2
0
        public void All_implemented_interfaces_should_be_registered_for_func()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.ConfigureComponent(() => new ComponentWithMultipleInterfaces(), DependencyLifecycle.InstancePerCall);
            Assert.True(configureComponents.HasComponent(typeof(ISomeInterface)));
            Assert.True(configureComponents.HasComponent(typeof(ISomeOtherInterface)));
            Assert.True(configureComponents.HasComponent(typeof(IYetAnotherInterface)));

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreEqual(1, builder.GetServices(typeof(IYetAnotherInterface)).Count());
        }
Пример #3
0
        public void Builders_should_not_determine_existence_by_building_components()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            InitializeBuilder(configureComponents);

            Assert.True(configureComponents.HasComponent(typeof(ExistingComponentWithUnsatisfiedDependency)));
        }
Пример #4
0
        public void Non_existing_components_should_return_false()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            InitializeBuilder(configureComponents);

            Assert.False(configureComponents.HasComponent(typeof(NonExistingComponent)));
        }
Пример #5
0
        public void Generic_interfaces_should_be_registered()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.ConfigureComponent(typeof(ComponentWithGenericInterface),
                                                   DependencyLifecycle.InstancePerCall);

            Assert.True(configureComponents.HasComponent(typeof(ISomeGenericInterface <string>)));
        }