public void Create_Throws_InvalidOperationException_When_No_SessionProvider_Has_Been_Set()
 {
     var factory = new NHUnitOfWorkFactory();
     Assert.Throws<InvalidOperationException>(
         () => factory.Create()
         );
 }
        public void Create_Returns_NHUnitOfWork_Instance_When_DataContextProvider_Has_Been_Set()
        {
            NHUnitOfWorkFactory.SetSessionProvider(() => MockRepository.GenerateStub <ISession>());

            var factory     = new NHUnitOfWorkFactory();
            var uowInstance = factory.Create();

            Assert.That(uowInstance, Is.Not.Null);
            Assert.That(uowInstance, Is.TypeOf(typeof(NHUnitOfWork)));

            NHUnitOfWorkFactory.SetSessionProvider(null);
        }
        public void Create_Returns_LinqToSqlUnitOfWork_Instance_When_DataContextProvider_Has_Been_Set()
        {
            NHUnitOfWorkFactory.SetSessionProvider(() => MockRepository.GenerateStub<ISession>());

            var factory = new NHUnitOfWorkFactory();
            var uowInstance = factory.Create();

            Assert.That(uowInstance, Is.Not.Null);
            Assert.That(uowInstance, Is.TypeOf(typeof(NHUnitOfWork)));

            NHUnitOfWorkFactory.SetSessionProvider(null);
        }
Example #4
0
        public static void Main()
        {
            var sessionFactory    = OWDatabaseConfiguration.Configure("thread_static");
            var unitOfWorkFactory = new NHUnitOfWorkFactory(sessionFactory);

            using (var unitOfWork = unitOfWorkFactory.Create()) {
                var notionRepo = new NHRepository <NotionType>(sessionFactory);
                notionRepo.AddOrUpdate(new NotionType(Constants.NotionType));
                notionRepo.AddOrUpdate(new NotionType(Constants.ActionType));

                var relationRepo = new NHRepository <RelationType>(sessionFactory);
                relationRepo.AddOrUpdate(new RelationType(Constants.AssociationType));
                relationRepo.AddOrUpdate(new RelationType(Constants.TaxonomyType));
                relationRepo.AddOrUpdate(new RelationType(Constants.MeronomyType));

                unitOfWork.Commit();
            }
        }
        public void Create_Throws_InvalidOperationException_When_No_SessionProvider_Has_Been_Set()
        {
            var factory = new NHUnitOfWorkFactory();

            Assert.Throws <InvalidOperationException>(() => factory.Create());
        }