Beispiel #1
0
        protected virtual void OnTestFixtureSetUp()
        {
            IoC.Reset();

            InitializeNHibernateAndIoC(ContainerFilePath,
                                       GetDatabaseEngine(),
                                       GetDatabaseName(),
                                       GetMappingInfo(),
                                       GetNHibernateProperties(),
                                       cfg => {
                // Listner 가 대량 Data 처리 시에는 속도를 느리게 하는 주범입니다... 테스트 시에는 굳이 필요없습니다.

                //if(IsDebugEnabled)
                //    log.Debug("CurrentContext의 NHibernate Configuration이 생성되었습니다. 여기에 Event Listener를 추가합니다...");

                //if(cfg != null)
                //{
                //    cfg.SetListener(NHibernate.Event.ListenerType.PreInsert, new UpdateTimestampEventListener());
                //    cfg.SetListener(NHibernate.Event.ListenerType.PreUpdate, new UpdateTimestampEventListener());
                //}
            },
                                       new PascalNamingConvention {
                PropertyWithClassNames = new[] { "Code", "Name" }
            });

            CurrentContext.CreateUnitOfWork();

            if (UnitOfWork.CurrentSessionFactory.IsSQLite())
            {
                UnitOfWork.CurrentSession.CreateSQLQuery("PRAGMA synchronous=0;").ExecuteUpdate();
                //UnitOfWork.CurrentSession.CreateSQLQuery("PRAGMA count_changes=2;").ExecuteUpdate();
                UnitOfWork.CurrentSession.CreateSQLQuery("PRAGMA temp_store=2;").ExecuteUpdate();
                UnitOfWork.CurrentSession.CreateSQLQuery("PRAGMA journal_mode=memory;").ExecuteUpdate();
            }
        }
 public void TestInitialize()
 {
     Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     InitializeNHibernateAndIoC(PersistenceFramework.NHibernate,
                                Path.GetFullPath(@"Repository\Windsor.config"),
                                MappingInfo.FromAssemblyContaining <Parent>());
     CurrentContext.CreateUnitOfWork();
 }
        public virtual void SetUp()
        {
            MappingInfo from = MappingInfo.From(typeof(Cargo).Assembly, typeof(HibernateRepository <>).Assembly);

            InitializeNHibernateAndIoC(PersistenceFramwork, RhinoContainerConfig, DatabaseEngine.SQLite, from);

            CurrentContext.CreateUnitOfWork();
            LoadData();
        }
 protected void VerifyCanCreateUseAndDisposeUnitOfWork()
 {
     try {
         CurrentContext.CreateUnitOfWork();
         Console.WriteLine(UnitOfWork.CurrentSession.Connection.ConnectionString);
         UnitOfWork.CurrentSession.Save(new GuidEntityForTesting());
         UnitOfWork.CurrentSession.Flush();
     }
     finally {
         CurrentContext.DisposeUnitOfWork();
     }
 }
        protected virtual void OnTestFixtureSetUp()
        {
            InitializeNHibernateAndIoC(ContainerFilePath,
                                       GetDatabaseEngine(),
                                       GetDatabaseName(),
                                       GetMappingInfo(),
                                       GetNHibernateProperties(),
                                       new OracleNamingConvention {
                PropertyWithClassNames = new[] { "Code", "Name" }
            });

            CurrentContext.CreateUnitOfWork();
        }
        public void NotifiedOnUnitOfWorkStart()
        {
            IoC.Container.AddComponent("IUnitOfWorkAware", typeof(IUnitOfWorkAware), typeof(UnitOfWorkAwareImplementor));
            CurrentContext.CreateUnitOfWork();
            UnitOfWorkAwareImplementor resolve = (UnitOfWorkAwareImplementor)IoC.Resolve <IUnitOfWorkAware>();

            Assert.AreEqual(1, resolve.StartedCalled);
            Assert.AreEqual(0, resolve.DisposingCalled);
            Assert.AreEqual(0, resolve.DisposedCalled);
            CurrentContext.DisposeUnitOfWork();
            Assert.AreEqual(1, resolve.StartedCalled);
            Assert.AreEqual(1, resolve.DisposingCalled);
            Assert.AreEqual(1, resolve.DisposedCalled);
        }
        protected virtual void OnTestFixtureSetUp()
        {
            InitializeNHibernateAndIoC(ContainerFilePath,
                                       GetDatabaseEngine(),
                                       GetDatabaseName(),
                                       GetMappingInfo(),
                                       GetNHibernateProperties(),
                                       cfg => {
                cfg.SetListener(NHibernate.Event.ListenerType.PreInsert, new UpdateTimestampEventListener());
                cfg.SetListener(NHibernate.Event.ListenerType.PreUpdate, new UpdateTimestampEventListener());
            },
                                       new PascalNamingConvention {
                PropertyWithClassNames = new[] { "Code", "Name" }
            });

            CurrentContext.CreateUnitOfWork();
        }
Beispiel #8
0
        protected void VerifyCanCreateUseAndDisposeNestedUnitOfWork()
        {
            Assert.AreEqual(-1, CurrentContext.UnitOfWorkNestingLevel, "level before starting UoW = -1");

            CurrentContext.CreateUnitOfWork();
            Assert.AreEqual(0, CurrentContext.UnitOfWorkNestingLevel, "level after starting UoW = 0");

            CurrentContext.CreateNestedUnitOfWork();
            Assert.AreEqual(1, CurrentContext.UnitOfWorkNestingLevel, "level after starting nested UoW = 1");

            UnitOfWork.CurrentSession.Save(new AREntity());
            UnitOfWork.CurrentSession.Flush();
            CurrentContext.DisposeUnitOfWork();

            //this is happening in the original UoW
            UnitOfWork.CurrentSession.Save(new AREntity());
            UnitOfWork.CurrentSession.Flush();
            CurrentContext.DisposeUnitOfWork();
        }
        protected void VerifyCanCreateUseAndDisposeNestedUnitOfWork()
        {
            Assert.AreEqual(-1, CurrentContext.UnitOfWorkNestingLevel, "level before starting UnitOfWork = -1");

            CurrentContext.CreateUnitOfWork();
            Assert.AreEqual(0, CurrentContext.UnitOfWorkNestingLevel, "level before starting UnitOfWork = 0");

            CurrentContext.CreateNestedUnitOfWork();
            Assert.AreEqual(1, CurrentContext.UnitOfWorkNestingLevel, "level after staring Nested UnitOfWork = 1");

            // in nested unit-of-work
            UnitOfWork.CurrentSession.Save(new GuidEntityForTesting());
            UnitOfWork.CurrentSession.Flush();
            CurrentContext.DisposeUnitOfWork();

            // in original unit-of-work
            UnitOfWork.CurrentSession.Save(new GuidEntityForTesting());
            UnitOfWork.CurrentSession.Flush();
            CurrentContext.DisposeUnitOfWork();
        }
        protected void VerifyCanCreateUseAndDisposeSession()
        {
            ISession session = null;

            try {
                if (IoC.IsNotInitialized)
                {
                    IoC.Initialize();
                }
                CurrentContext.CreateUnitOfWork();

                session = CurrentContext.CreateSession();
                Assert.IsNotNull(session);
                session.Save(new GuidEntityForTesting());
                session.Flush();
            }
            finally {
                CurrentContext.DisposeSession(session);
                CurrentContext.DisposeUnitOfWork();
            }
        }
Beispiel #11
0
        public virtual void CallingCreateUnitOfWorkMoreThanOnceIsNotAllowed()
        {
            InitializeNHibernateAndIoC(WindsorFilePath, DatabaseEngine.SQLite, "");

            CurrentContext.CreateUnitOfWork();
            try
            {
                CurrentContext.CreateUnitOfWork();
                Assert.Fail("Exception was expected");
            }
            catch (InvalidOperationException e)
            {
                string message =
                    "Cannot create a nested UnitOfWork with this method. Use CreateNestedUnitOfWork() instead";
                Assert.AreEqual(message, e.Message);
            }
            finally
            {
                CurrentContext.DisposeUnitOfWork();
            }
        }
 public void TestInitialize()
 {
     CurrentContext.CreateUnitOfWork();
 }
 protected virtual void OnTestFixtureSetUp()
 {
     InitializeNHibernateAndIoC(ContainerFilePath, GetDatabaseEngine(), GetDatabaseName(), GetMappingInfo(),
                                GetNHibernateProperties());
     CurrentContext.CreateUnitOfWork();
 }
Beispiel #14
0
 public void TestInitialize()
 {
     CurrentContext.CreateUnitOfWork();
     CreateObjectsInDb();
 }
 public void WhenNotRegisteredUnitOfWorkStarts()
 {
     CurrentContext.CreateUnitOfWork();
     Assert.IsTrue(UnitOfWork.IsStarted);
 }