示例#1
0
        public void FlushWillPersistChangesMadeAfterCallingSaveAsASeperateUpdate()
        {
            Customer customer = Om.CreateCustomer();

            Nh.CurrentSession.Save(customer);

            customer.Name = "New name";
            Nh.FlushSessionToDbAndClear();

            Assert.That(customer.Name, Is.EqualTo(Nh.GetFromDb <Customer>(customer.Id).Name));
            Assert.That(customer.ConcurrencyId, Is.EqualTo(2));
        }
示例#2
0
        public void DisposingOfTransactionWillRollbackTransactionIfNotCommitted()
        {
            Customer c = Om.CreateCustomer();

            using (Nh.CurrentSession.BeginTransaction())
            {
                Nh.CurrentSession.SaveOrUpdate(c);
                Nh.FlushSessionToDbAndClear();
            }

            Assert.That(Nh.CurrentSession.Get <Customer>(c.Id),
                        Is.Null,
                        "Customer not found in database");
        }
示例#3
0
        public void FlushWillReachNewObjectsAttachedToAPersistenceInstanceAfterSave()
        {
            Customer c = Om.CreateCustomer();

            Nh.CurrentSession.SaveOrUpdate(c);

            //note that customer already associated with session
            Address a = Om.CreateAddress();

            c.AddAddress(a);

            Nh.FlushSessionToDbAndClear();

            var loadedCustomer = Nh.CurrentSession.Get <Customer>(c.Id);

            Assert.That(loadedCustomer.Addresses.Count, Is.EqualTo(1));
        }
示例#4
0
        public void FlushInsideATransactionWillNotBeCommittedUnlessTransactionCommitted()
        {
            Customer c = Om.CreateCustomer();

            using (ITransaction transaction = Nh.CurrentSession.BeginTransaction())
            {
                Nh.CurrentSession.SaveOrUpdate(c);
                Nh.FlushSessionToDbAndClear();
                Assert.That(Nh.CurrentSession.Get <Customer>(c.Id),
                            Is.Not.Null,
                            "Customer saved in database");
                transaction.Rollback();
            }

            Nh.CurrentSession.Clear();
            Assert.That(Nh.CurrentSession.Get <Customer>(c.Id),
                        Is.Null,
                        "Customer not found in database");
        }