Exemple #1
0
        public void WithoutForceSaveGeneratesException()
        {
            User user = DomainObjectDataHelper.CreateValidUser();

            user.LoginID = "JF63KD834K";

            Assert.IsTrue(user.IsTransient());
            _userRepository.DbContext.BeginTransaction();
            _userRepository.EnsurePersistent(user);
            _userRepository.DbContext.RollbackTransaction();

            Assert.IsFalse(user.IsTransient());                         //Make sure the user is saved

            NHibernateSessionManager.Instance.GetSession().Evict(user); //get the user out of the local cache

            try
            {
                _userRepository.DbContext.BeginTransaction();
                _userRepository.EnsurePersistent(user); //Don't force the save, will generate an exception
                Assert.Fail("Expected Exception of type StaleObjectStateException");
            }
            catch (StaleObjectStateException)
            {
            }
        }
Exemple #2
0
        public void CanRollBackAddedUser()
        {
            User user = DomainObjectDataHelper.CreateValidUser();

            user.LoginID = "JF63KD834K";

            Assert.IsTrue(user.IsTransient());
            _userRepository.DbContext.BeginTransaction();
            _userRepository.EnsurePersistent(user);
            int userId = user.Id;

            _userRepository.DbContext.RollbackTransaction();

            Assert.IsFalse(user.IsTransient());                         //Make sure the user is saved

            NHibernateSessionManager.Instance.GetSession().Evict(user); //get the user out of the local cache

            User retrievedUser = _userRepository.GetNullableById(userId);

            Assert.IsNull(retrievedUser);
            Assert.AreEqual(10, _userRepository.GetAll().Count);
        }
Exemple #3
0
        public void CanForceSaveWithoutException()
        {
            User user = DomainObjectDataHelper.CreateValidUser();

            user.LoginID = "JF63KD834K";

            Assert.IsTrue(user.IsTransient());
            _userRepository.DbContext.BeginTransaction();
            _userRepository.EnsurePersistent(user);
            _userRepository.DbContext.RollbackTransaction();

            Assert.IsFalse(user.IsTransient());                         //Make sure the user is saved

            NHibernateSessionManager.Instance.GetSession().Evict(user); //get the user out of the local cache


            _userRepository.DbContext.BeginTransaction();
            _userRepository.EnsurePersistent(user, true); //Force the save
            _userRepository.DbContext.CommitTransaction();

            Assert.AreEqual(11, _userRepository.GetAll().Count);
        }
Exemple #4
0
        public void CanSaveNewUser()
        {
            User user = DomainObjectDataHelper.CreateValidUser();

            user.LoginID = "GBH756H4D3";

            Assert.IsTrue(user.IsTransient());
            _userRepository.DbContext.BeginTransaction();
            _userRepository.EnsurePersistent(user);
            _userRepository.DbContext.CommitTransaction();

            Assert.IsFalse(user.IsTransient());                         //Make sure the user is saved

            NHibernateSessionManager.Instance.GetSession().Evict(user); //get the user out of the local cache

            //Now get the user back out
            int userId = user.Id;

            User retrievedUser = _userRepository.GetNullableById(userId);

            Assert.IsNotNull(retrievedUser);
            Assert.AreEqual("GBH756H4D3", retrievedUser.LoginID); //Make sure it is the correct user
            Assert.AreEqual(11, _userRepository.GetAll().Count);
        }
Exemple #5
0
 protected override void LoadData()
 {
     DomainObjectDataHelper.LoadDomainDataUsers(_userRepository);
 }