From: Michael D. <mik...@us...> - 2004-09-15 14:00:24
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8270/NHibernate.Test Modified Files: FooBarTest.cs Log Message: Added tests to verify an old version can't update the db Index: FooBarTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/FooBarTest.cs,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** FooBarTest.cs 11 Sep 2004 00:10:39 -0000 1.65 --- FooBarTest.cs 15 Sep 2004 14:00:16 -0000 1.66 *************** *** 1881,1884 **** --- 1881,1890 ---- s.Close(); + // grab a version of g that is old and hold onto it until later + // for a StaleObjectException check. + ISession sOld = sessions.OpenSession(); + GlarchProxy gOld = (GlarchProxy)sOld.Load( typeof(Glarch), gid ); + sOld.Close(); + s = sessions.OpenSession(); g = (GlarchProxy)s.Load( typeof(Glarch), gid ); *************** *** 1894,1897 **** --- 1900,1930 ---- s.Close(); + // now that g has been changed verify that we can't go back and update + // it with an old version of g + bool isStale = false; + sOld = sessions.OpenSession(); + gOld.Name = "should not update"; + try + { + sOld.Update( gOld, gid ); + sOld.Flush(); + sOld.Close(); + } + catch(Exception e) + { + Exception exc = e; + while( e!=null ) + { + if( exc is StaleObjectStateException ) + { + isStale = true; + break; + } + exc = exc.InnerException; + } + } + + Assert.IsTrue( isStale, "Did not catch a stale object exception when updating an old GlarchProxy." ); + s = sessions.OpenSession(); g = (GlarchProxy)s.Load( typeof(Glarch), gid ); |