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); } }
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 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); } }