예제 #1
0
        public void LazyProxyRemainsAttachedToNewSessionWhenAccessed()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(ObjectWithLazyAssociation2),
                                           typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();

            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var obj = new ObjectWithLazyAssociation2();

            obj.LazyObj = lazy;
            ActiveRecordMediator.Save(obj);

            var objFromDb = (ObjectWithLazyAssociation2)ActiveRecordMediator.FindByPrimaryKey(typeof(ObjectWithLazyAssociation2), obj.Id);

            using (new SessionScope()) {
                Assert.AreEqual("test", objFromDb.LazyObj.Title);
                var objSession = (objFromDb.LazyObj as NHibernate.Proxy.INHibernateProxy).HibernateLazyInitializer.Session;
                Assert.IsTrue(objSession.IsConnected && objSession.IsOpen, "Session did not remain open after accessing lazy object within a new SessionScope");
            }
        }
예제 #2
0
        public void LoadingLazyObjectOutsideOfScopeDoesNotInitializeIfARByteCodeIsUsed()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();

            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var lazyFromDb = (VeryLazyObject2)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject2), lazy.Id);

            Assert.False(NHibernate.NHibernateUtil.IsInitialized(lazyFromDb));
        }
예제 #3
0
        public void CanLoadLazyBelongsToOutsideOfScope()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(ObjectWithLazyAssociation), typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();
            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var obj = new ObjectWithLazyAssociation();
            obj.LazyObj = lazy;
            ActiveRecordMediator.Save(obj);

            var objFromDb = (ObjectWithLazyAssociation) ActiveRecordMediator.FindByPrimaryKey(typeof(ObjectWithLazyAssociation), obj.Id);
            Assert.False(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
            Assert.AreEqual("test", objFromDb.LazyObj.Title);
            Assert.True(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
        }
예제 #4
0
        public void CanLoadLazyBelongsToOutsideOfScope()
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(ObjectWithLazyAssociation), typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();

            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var obj = new ObjectWithLazyAssociation();

            obj.LazyObj = lazy;
            ActiveRecordMediator.Save(obj);

            var objFromDb = (ObjectWithLazyAssociation)ActiveRecordMediator.FindByPrimaryKey(typeof(ObjectWithLazyAssociation), obj.Id);

            Assert.False(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
            Assert.AreEqual("test", objFromDb.LazyObj.Title);
            Assert.True(NHibernate.NHibernateUtil.IsInitialized(objFromDb.LazyObj));
        }
예제 #5
0
        public void LoadingLazyObjectOutsideOfScopeDoesNotInitializeIfARByteCodeIsUsed() 
        {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();
            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var lazyFromDb = (VeryLazyObject2)ActiveRecordMediator.FindByPrimaryKey(typeof(VeryLazyObject2), lazy.Id);
            Assert.False(NHibernate.NHibernateUtil.IsInitialized(lazyFromDb));
        }
예제 #6
0
        public void LazyProxyRemainsAttachedToNewSessionWhenAccessed() {
            ActiveRecordStarter.Initialize(GetConfigSource(), typeof(ScopelessLazy), typeof(ObjectWithLazyAssociation2),
                                           typeof(VeryLazyObject2));

            Recreate();

            var lazy = new VeryLazyObject2();
            lazy.Title = "test";
            ActiveRecordMediator.Save(lazy);

            var obj = new ObjectWithLazyAssociation2();
            obj.LazyObj = lazy;
            ActiveRecordMediator.Save(obj);

            var objFromDb = (ObjectWithLazyAssociation2)ActiveRecordMediator.FindByPrimaryKey(typeof(ObjectWithLazyAssociation2), obj.Id);
            using (new SessionScope()) {
                Assert.AreEqual("test", objFromDb.LazyObj.Title);
                var objSession = (objFromDb.LazyObj as NHibernate.Proxy.INHibernateProxy).HibernateLazyInitializer.Session;
                Assert.IsTrue(objSession.IsConnected && objSession.IsOpen, "Session did not remain open after accessing lazy object within a new SessionScope");
            }
        }