/// <summary>
        /// Initialize current facility
        /// </summary>
        protected override void Init() {
            if(IsDebugEnabled)
                log.Debug("Multiple UnitOfWork를 위한 Facility를 초기화 합니다.");

            Kernel.Register(Component.For(typeof(INHRepository<>)).ImplementedBy(typeof(NHRepository<>)));

            var multipleUowFactory = new NHMultipleUnitOfWorkFactory();

            if(_configs == null) {
                if(IsDebugEnabled)
                    log.Debug("프로그램에서 지정한 환경설정 정보가 없으므로, 환경설정 파일에서 정보를 얻습니다.");

                AssertConfigurations();
                _configs = FacilityConfig.Children.Select(factoryConfig => new NHUnitOfWorkFacilityConfig(factoryConfig)).ToArray();
                multipleUowFactory.DefaultFactoryName = _defaultFactoryName;
            }

            if(IsDebugEnabled)
                log.Debug("환경설정에 지정된 Factory 정보로부터, NHUnitOfWorkFactory를 생성합니다.");

            foreach(NHUnitOfWorkFacilityConfig config in _configs) {
                var nestedUnitOfWorkFactory = new NHUnitOfWorkFactory(config.NHibernateConfigurationFilename);
                nestedUnitOfWorkFactory.RegisterSessionFactory(CreateSessionFactory(config));
                multipleUowFactory.Add(nestedUnitOfWorkFactory);
            }

            Kernel.Register(Component.For<IUnitOfWorkFactory>().Instance(multipleUowFactory));
            // Kernel.AddComponentInstance<IUnitOfWorkFactory>(multipleUowFactory);

            if(IsDebugEnabled)
                log.Debug("Kernel에 NHMultipleUnitOfWorkFactory의 인스턴스를 등록했습니다.");
        }
 public void Create_Throws_InvalidOperationException_When_No_SessionProvider_Has_Been_Set()
 {
     var factory = new NHUnitOfWorkFactory();
     Assert.Throws<InvalidOperationException>(
         () => factory.Create()
         );
 }
        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
        //protected ISession OrdersDomainSession { get; set; }
        //protected ISession HRDomainSession { get; set; }
        public static void Setup()
        {
            if (File.Exists("Test.sdf")) File.Delete("Test.sdf");
            using (var engine = new System.Data.SqlServerCe.SqlCeEngine(ConnectionString))
            {
                engine.CreateDatabase();
            }
            var cnf = Fluently.Configure()
            .Database(MsSqlCeConfiguration.Standard
            .ConnectionString(((ConnectionStringBuilder cs) => cs.Is(ConnectionString)))
            .Dialect <MsSqlCe40Dialect>())
            .Mappings(mappings => mappings.FluentMappings.AddFromAssembly(typeof(Order).Assembly).ExportTo("."))
            .ExposeConfiguration(x => new SchemaExport(x).Execute(false, true, false));//, GetConnection(), null));
            //var config = cnf.BuildConfiguration()
            //    .SetProperty(NHibernateCfg.Environment.ReleaseConnections, "on_close");
            OrdersDomainFactory = cnf.BuildConfiguration().BuildSessionFactory();

            cnf  = Fluently.Configure()
            .Database(MsSqlCeConfiguration.Standard
            .ConnectionString(((ConnectionStringBuilder cs) => cs.Is(ConnectionString)))
            .Dialect <MsSqlCe40Dialect>())
            .Mappings(mappings => mappings.FluentMappings.AddFromAssembly(typeof(SalesPerson).Assembly).ExportTo("."))
            .ExposeConfiguration(x => new SchemaExport(x).Execute(false, true, false));//, GetConnection(), null));
            //config = cnf.BuildConfiguration()
            //    .SetProperty(NHibernateCfg.Environment.ReleaseConnections, "on_close");
            HRDomainFactory = cnf.BuildConfiguration().BuildSessionFactory();
            //OrdersDomainSession = OrdersDomainFactory.OpenSession(GetConnection());
            //HRDomainSession = HRDomainFactory.OpenSession(GetConnection());
            NHUnitOfWorkFactory unitOfWorkFactory = new NHUnitOfWorkFactory();
            unitOfWorkFactory.RegisterSessionFactoryProvider(() => OrdersDomainFactory);
            unitOfWorkFactory.RegisterSessionFactoryProvider(() => HRDomainFactory);
            UnitOfWorkSettings.DefaultIsolation = System.Transactions.IsolationLevel.ReadCommitted;
            //IUnitOfWork uow = UnitOfWorkFactory.Create();
            var dependencyResolverFactory = new Mock<IDependencyResolverFactory>();
            var dependencyResolver = new Mock<ICustomDependencyResolver>();
            var logFacotry = new Mock<ILogFactory>();
            var cacheManager = new Mock<ICacheManager>();
            dependencyResolverFactory.Setup(x => x.CreateInstance()).Returns(dependencyResolver.Object);
            dependencyResolver.Setup(x => x.GetService(typeof(ILogFactory))).Returns(logFacotry.Object);
            dependencyResolver.Setup(x => x.GetService(typeof(ICacheManager), It.IsAny<string>())).Returns(cacheManager.Object);
            dependencyResolver.Setup(x => x.GetService(typeof(IUnitOfWorkFactory))).Returns(unitOfWorkFactory);
            //cacheManager.Setup(x => x.Get<IUnitOfWork>(It.IsAny<string>())).Returns(uow);
            IoC.InitializeWith(dependencyResolverFactory.Object);
            App.Data.TransactionManager transactionManager = new Data.TransactionManager();
            cacheManager.Setup(x => x.Get<ITransactionManager>(It.IsAny<string>())).Returns(transactionManager);
        }