public void Installers_defined_after_SessionFactoryResolver_are_processed()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            // Register installer prior to registering
            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<DefaultInstaller>()
                );

            Assert.IsTrue(sessionFactoryResolver.IsAliasDefined("default-installer"));
        }
        public void Default_installer_recognised()
        {
            using (var container = new WindsorContainer())
            {
                var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

                // Register installer prior to registering
                container.Register(
                    Component.For<IConfigurationBuilder>()
                        .ImplementedBy<TestConfigurationBuilder>(),
                    Component.For<IConfigurationBuilder>()
                        .ImplementedBy<NonDefaultInstaller>()
                    );

                Assert.AreEqual("testdb", sessionFactoryResolver.DefaultAlias);

                var testdbSessionFactory = sessionFactoryResolver.GetSessionFactory("testdb");
                var defaultSessionFactory = sessionFactoryResolver.GetSessionFactory(null);

                Assert.AreSame(testdbSessionFactory, defaultSessionFactory);
            }
        }
Example #3
0
 private void RegisterSessionFactoryResolver()
 {
     var sessionFactoryResolver = new SessionFactoryResolver(Kernel);
     Kernel.Register(Component.For<ISessionFactoryResolver>().Instance(sessionFactoryResolver));
 }
        public void Installers_with_dependencies_are_processed_when_possible()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            // Register installer prior to registering
            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<InstallerWithDependency>()
                );

            Assert.IsFalse(sessionFactoryResolver.IsAliasDefined("installer-with-dependency"));

            container.Register(Component.For<DependencyClass>());

            Assert.IsTrue(sessionFactoryResolver.IsAliasDefined("installer-with-dependency"));
        }
        public void Unknown_alias()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<NonDefaultInstaller>()
                );

            try
            {
                var sessionFactory = sessionFactoryResolver.GetSessionFactory("some-random-alias");
                Assert.Fail("Exception expected");
            }
            catch (NHibernateFacilityException ex)
            {
                Assert.AreEqual("Unknown session factory alias: some-random-alias", ex.Message);
            }
        }
        public void Throws_exception_when_two_installers_have_the_same_name()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            // Register installer prior to registering
            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<NonDefaultInstaller>()
                );

            try
            {
                // Register installer prior to registering
                container.Register(
                    Component.For<IConfigurationBuilder>()
                        .ImplementedBy<NonDefaultInstaller>()
                        .Named("another-name-that-does-not-clash")
                    );
                Assert.Fail("Exception expected");
            }
            catch (NHibernateFacilityException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("Multiple IConfigurationBuilders have alias of non-default-installer:"));
            }
        }
        public void Throws_exception_when_two_default_installers()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            // Register installer prior to registering
            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<DefaultInstaller>()
                );

            try
            {
                // Register installer prior to registering
                container.Register(
                    Component.For<IConfigurationBuilder>()
                        .ImplementedBy<AnotherDefaultInstaller>()
                    );
                Assert.Fail("Exception expected");
            }
            catch (NHibernateFacilityException ex)
            {
                Assert.IsTrue(ex.Message.StartsWith("Multiple IConfigurationBuilders have IsDefault=true:"));
            }
        }
        public void No_default_installer()
        {
            var container = new WindsorContainer();
            var sessionFactoryResolver = new SessionFactoryResolver(container.Kernel);

            Assert.IsNull(sessionFactoryResolver.DefaultAlias);

            container.Register(
                Component.For<IConfigurationBuilder>()
                    .ImplementedBy<NonDefaultInstaller>()
                );

            Assert.IsNull(sessionFactoryResolver.DefaultAlias);

            try
            {
                var sessionFactory = sessionFactoryResolver.GetSessionFactory(null);
                Assert.Fail("Exception expected");
            }
            catch (NHibernateFacilityException ex)
            {
                Assert.AreEqual("No default session factory defined", ex.Message);
            }
        }