I have a test that I am running that tests the ability to modify a row
of a table.  This table is being updated in the database, however the
retrieval process is not reflecting this change thus my test is
failing.

Test:

        [Test]
        public void CanModifyCWTWeightBreakdown()
        {
            int id =  _RatingLogic.GetAllCWTWeightBreakdowns()[0].Id;

            _RatingLogic.ModifyCWTWeightBreakdown(id, 0, 1985, 15M,
29);

            Assert.AreEqual(29, _Provider.GetCWTWeightBreakdownById
(id).UserEdited.Id);

        }

Logic Layer:


        public void ModifyCWTWeightBreakdown(int weightBreakdownId,
int minWeight, int maxWeight, decimal rate, int userId)
        {

            if (!CWTWeightBreakdownExists(weightBreakdownId))
                throw new Exception("Weight breakdown does not
exist");

            CWTWeightBreakdown weightBreakdown =
provider.GetCWTWeightBreakdownById(weightBreakdownId);

            weightBreakdown.MinimumWeight = minWeight;
            weightBreakdown.MaximumWeight = maxWeight;
            weightBreakdown.Rate = rate;
            weightBreakdown.UserEdited = provider.GetUserById(userId);

            provider.ModifyCWTWeightBreakdown(weightBreakdown);
        }

Data Layer:

        public void ModifyCWTWeightBreakdown(CWTWeightBreakdown
weightBreakdown)
        {
            if (weightBreakdown.UserEdited == null)
                throw new ArgumentException("UserEdited may not be
null.");

            int retryCount = 0;
            Exception lastException = null;

            while (retryCount < 3)
            {
                try
                {
                    weightBreakdown.DateEdited = DateTime.Now;

                    session.Transaction.Begin();

                    session.Update(weightBreakdown);
                    session.Flush();

                    session.Transaction.Commit();

                    return;
                }
                catch (Exception ex)
                {
                    if (session.Transaction.IsActive)
                        session.Transaction.Rollback();

                    ResetSession();

                    retryCount++;

                    lastException = ex;

                    Thread.Sleep(300);
                }
            }

            if (retryCount == 3 && lastException != null)
                throw lastException;
        }


I step through this in the debugger and it is properly being set, but
when I retrieve it within the assert statement it still pulls up 1 as
the UserEdited.Id which is a result for a previous test.  I am not
understanding why it isn't reflecting the change despite no exceptions
being thrown and the database properly updating.  This of course runs
perfectly if I run the test by itself.  It is because of the previous
test I know, but I still thought NHibernate would reflect the change
despite the previous modification, especially since it is working
properly with the DB.


Thanks again and I hope I am not a bother to the list,
Josh Rogers
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to