public void Singleton_components_should_yield_the_same_instance()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.AreEqual(builder.Build(typeof(SingletonComponent)), builder.Build(typeof(SingletonComponent)));
     }
 }
 public void Requesting_an_unregistered_component_should_throw()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.That(() => builder.Build(typeof(UnregisteredComponent)), Throws.Exception);
     }
 }
 public void Resolving_all_components_of_unregistered_types_should_give_empty_list()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.IsEmpty(builder.BuildAll(typeof(UnregisteredComponent)));
     }
 }
        public void When_circular_ref_exists_between_container_and_builder_should_not_infinite_loop()
        {
            var builder = TestContainerBuilder.ConstructBuilder();

            Debug.WriteLine("Trying " + builder.GetType().Name);
            builder.RegisterSingleton(builder.GetType(), builder);
            builder.Dispose();
        }
 public void Lambda_singlecall_components_should_yield_unique_instances()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.AreNotEqual(builder.Build(typeof(SingleCallLambdaComponent)), builder.Build(typeof(SingleCallLambdaComponent)));
     }
 }
 public void Non_existing_components_should_return_false()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.False(builder.HasComponent(typeof(NonExistingComponent)));
     }
 }
 public void Builders_should_not_determine_existence_by_building_components()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.True(builder.HasComponent(typeof(ExistingComponentWithUnsatisfiedDependency)));
     }
 }
Esempio n. 8
0
        public void Singlecall_components_should_yield_unique_instances()
        {
            var serviceCollection = new ServiceCollection();

            InitializeServices(serviceCollection);
            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreNotEqual(builder.GetService <SinglecallComponent>(), builder.GetService <SinglecallComponent>());
        }
Esempio n. 9
0
        public void Concrete_classes_should_get_the_same_lifecycle_as_their_interfaces()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(SingletonComponent), DependencyLifecycle.SingleInstance);

                Assert.AreSame(builder.Build(typeof(SingletonComponent)), builder.Build(typeof(ISingletonComponent)));
            }
        }
 public void Lambda_uow_components_should_resolve_from_main_container()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         InitializeBuilder(builder);
         Assert.NotNull(builder.Build(typeof(LambdaComponentUoW)));
     }
     //Not supported by typeof(WindsorObjectBuilder));
 }
Esempio n. 11
0
        public void Resolving_all_components_of_unregistered_types_should_give_empty_list()
        {
            var serviceCollection = new ServiceCollection();

            InitializeServices(serviceCollection);
            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.IsEmpty(builder.GetServices(typeof(UnregisteredComponent)));
        }
Esempio n. 12
0
        public void Lambda_singleton_components_should_yield_the_same_instance()
        {
            var serviceCollection = new ServiceCollection();

            InitializeServices(serviceCollection);
            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreEqual(builder.GetService(typeof(SingletonLambdaComponent)), builder.GetService(typeof(SingletonLambdaComponent)));
        }
Esempio n. 13
0
        public void A_registration_should_update_default_component_for_interface()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerCall);
                builder.Configure(typeof(SomeOtherClass), DependencyLifecycle.InstancePerCall);

                Assert.IsInstanceOf <SomeOtherClass>(builder.Build(typeof(ISomeInterface)));
            }
        }
Esempio n. 14
0
        public void Generic_interfaces_should_be_registered()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(ComponentWithGenericInterface),
                                  DependencyLifecycle.InstancePerCall);

                Assert.True(builder.HasComponent(typeof(ISomeGenericInterface <string>)));
            }
        }
Esempio n. 15
0
        public void Should_support_lambdas_that_uses_other_components_registered_later()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(() => ((StaticFactory)builder.Build(typeof(StaticFactory))).Create(), DependencyLifecycle.InstancePerCall);
                builder.Configure(() => new StaticFactory(), DependencyLifecycle.SingleInstance);

                Assert.NotNull(builder.Build(typeof(ComponentCreatedByFactory)));
            }
        }
Esempio n. 16
0
        public void Multiple_registrations_of_the_same_component_should_be_allowed()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(DuplicateClass), DependencyLifecycle.InstancePerCall);
                builder.Configure(typeof(DuplicateClass), DependencyLifecycle.InstancePerCall);

                Assert.AreEqual(1, builder.BuildAll(typeof(DuplicateClass)).Count());
            }
        }
        public void A_registration_should_be_allowed_to_be_updated()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.RegisterSingleton(typeof(ISingletonComponent), new SingletonComponent());
                builder.RegisterSingleton(typeof(ISingletonComponent), new AnotherSingletonComponent());

                Assert.IsInstanceOf <AnotherSingletonComponent>(builder.Build(typeof(ISingletonComponent)));
            }
        }
Esempio n. 18
0
 public void Register_singleton_should_be_supported()
 {
     using (var builder = TestContainerBuilder.ConstructBuilder())
     {
         var singleton = new SingletonComponent();
         builder.RegisterSingleton(typeof(ISingletonComponent), singleton);
         builder.RegisterSingleton(typeof(SingletonComponent), singleton);
         Assert.AreEqual(builder.Build(typeof(SingletonComponent)), singleton);
         Assert.AreEqual(builder.Build(typeof(ISingletonComponent)), singleton);
     }
 }
Esempio n. 19
0
        public void System_interfaces_should_not_be_auto_registered()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(ComponentWithSystemInterface),
                                  DependencyLifecycle.InstancePerCall);

                Assert.False(builder.HasComponent(typeof(IGrouping <string, string>)));
                Assert.False(builder.HasComponent(typeof(IDisposable)));
            }
        }
        public void Singleton_components_should_get_their_dependencies_autowired()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.RegisterSingleton(typeof(ISingletonComponentWithPropertyDependency), new SingletonComponentWithPropertyDependency());
                builder.RegisterSingleton(typeof(SingletonComponent), new SingletonComponent());

                var singleton = (SingletonComponentWithPropertyDependency)builder.Build(typeof(ISingletonComponentWithPropertyDependency));
                Assert.IsNotNull(singleton.Dependency);
            }
        }
Esempio n. 21
0
        public void Concrete_classes_should_get_the_same_lifecycle_as_their_interfaces()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.ConfigureComponent(typeof(SingletonComponent), DependencyLifecycle.SingleInstance);

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreSame(builder.GetService(typeof(SingletonComponent)), builder.GetService(typeof(ISingletonComponent)));
        }
        public void Lambda_uow_components_should_yield_the_same_instance()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                InitializeBuilder(builder);

                var instance1 = builder.Build(typeof(LambdaComponentUoW));
                var instance2 = builder.Build(typeof(LambdaComponentUoW));

                Assert.AreSame(instance1, instance2);
            }
        }
Esempio n. 23
0
        public void Lambda_uow_components_should_yield_the_same_instance()
        {
            var serviceCollection = new ServiceCollection();

            InitializeServices(serviceCollection);
            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            var instance1 = builder.GetService(typeof(LambdaComponentUoW));
            var instance2 = builder.GetService(typeof(LambdaComponentUoW));

            Assert.AreSame(instance1, instance2);
        }
        public void All_implemented_interfaces_should_be_registered_for_func()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(() => new ComponentWithMultipleInterfaces(), DependencyLifecycle.InstancePerCall);

                Assert.True(builder.HasComponent(typeof(ISomeInterface)));
                Assert.True(builder.HasComponent(typeof(ISomeOtherInterface)));
                Assert.True(builder.HasComponent(typeof(IYetAnotherInterface)));
                Assert.AreEqual(1, builder.BuildAll(typeof(IYetAnotherInterface)).Count());
            }
        }
Esempio n. 25
0
        public void Properties_configured_multiple_times_should_retain_only_the_last_configuration()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(DuplicateClass), DependencyLifecycle.SingleInstance);
                builder.ConfigureProperty(typeof(DuplicateClass), "SomeProperty", false);
                builder.ConfigureProperty(typeof(DuplicateClass), "SomeProperty", true); // this should remove/override the previous property setting

                var component = (DuplicateClass)builder.Build(typeof(DuplicateClass));
                Assert.True(component.SomeProperty);
            }
        }
Esempio n. 26
0
        public void A_registration_should_be_allowed_to_be_updated()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.RegisterSingleton(typeof(ISingletonComponent), new SingletonComponent());
            configureComponents.RegisterSingleton(typeof(ISingletonComponent), new AnotherSingletonComponent());

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.IsInstanceOf <AnotherSingletonComponent>(builder.GetService(typeof(ISingletonComponent)));
        }
Esempio n. 27
0
        public void Should_support_lambdas_that_uses_other_components_registered_later()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

            configureComponents.ConfigureComponent(s => ((StaticFactory)s.GetService(typeof(StaticFactory))).Create(), DependencyLifecycle.InstancePerCall);
            configureComponents.ConfigureComponent(() => new StaticFactory(), DependencyLifecycle.SingleInstance);

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.NotNull(builder.GetService(typeof(ComponentCreatedByFactory)));
        }
Esempio n. 28
0
        public void Multiple_registrations_of_the_same_component_should_be_allowed()
        {
            var serviceCollection   = new ServiceCollection();
            var configureComponents = new CommonObjectBuilder(serviceCollection);

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

            var builder = TestContainerBuilder.CreateServiceProvider(serviceCollection);

            Assert.AreEqual(1, builder.GetServices(typeof(DuplicateClass)).Count());
        }
Esempio n. 29
0
        public void Setter_dependencies_should_override_container_defaults()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(SomeClass), DependencyLifecycle.InstancePerCall);
                builder.Configure(typeof(ClassWithSetterDependencies), DependencyLifecycle.SingleInstance);
                builder.ConfigureProperty(typeof(ClassWithSetterDependencies), "InterfaceDependency", new SomeOtherClass());

                var component = (ClassWithSetterDependencies)builder.Build(typeof(ClassWithSetterDependencies));
                Assert.IsInstanceOf(typeof(SomeOtherClass), component.InterfaceDependency, "Explicitly set dependency should be injected, not container's default type");
            }
        }
        public void Instance_per_uow__components_should_be_disposed_when_the_child_container_is_disposed()
        {
            using (var builder = TestContainerBuilder.ConstructBuilder())
            {
                builder.Configure(typeof(InstancePerUoWComponent), DependencyLifecycle.InstancePerUnitOfWork);

                using (var nestedContainer = builder.BuildChildContainer())
                    nestedContainer.Build(typeof(InstancePerUoWComponent));
                Assert.True(InstancePerUoWComponent.DisposeCalled);
            }
            //Not supported bytypeof(SpringObjectBuilder));
        }