コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
        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);
            }
        }