From: Michael D. <mik...@us...> - 2004-08-09 18:45:03
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30029/NHibernate.Test Modified Files: FooBarTest.cs Log Message: Finished [Test] that had Serialization code in it. Index: FooBarTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/FooBarTest.cs,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** FooBarTest.cs 6 Aug 2004 14:50:34 -0000 1.53 --- FooBarTest.cs 9 Aug 2004 18:44:54 -0000 1.54 *************** *** 1113,1124 **** baz = (Baz)s.Find("select baz from baz in class NHibernate.DomainModel.Baz order by baz")[0]; Assert.AreEqual( 2, baz.StringSet.Count ); ! int i = 0; foreach(string key in baz.StringSet.Keys ) { // h2.0.3 doesn't have this because the Set has a first() and last() method ! i++; ! if(i==1) Assert.AreEqual( "one", key ); ! if(i==2) Assert.AreEqual( "two", key ); ! if(i>2) Assert.Fail("should not be more than 2 items in StringSet"); } Assert.AreEqual( 5, baz.Bag.Count ); --- 1113,1124 ---- baz = (Baz)s.Find("select baz from baz in class NHibernate.DomainModel.Baz order by baz")[0]; Assert.AreEqual( 2, baz.StringSet.Count ); ! int index = 0; foreach(string key in baz.StringSet.Keys ) { // h2.0.3 doesn't have this because the Set has a first() and last() method ! index++; ! if(index==1) Assert.AreEqual( "one", key ); ! if(index==2) Assert.AreEqual( "two", key ); ! if(index>2) Assert.Fail("should not be more than 2 items in StringSet"); } Assert.AreEqual( 5, baz.Bag.Count ); *************** *** 1140,1144 **** GlarchProxy g = new Glarch(); s.Save(g); ! baz.TopGlarchez['g'] = g; Hashtable map = new Hashtable(); map[bar] = g; --- 1140,1144 ---- GlarchProxy g = new Glarch(); s.Save(g); ! baz.TopGlarchez['G'] = g; Hashtable map = new Hashtable(); map[bar] = g; *************** *** 1175,1179 **** enumer = baz.FooToGlarch.Keys.GetEnumerator(); ! for( int j=0; j<2; j++ ) { enumer.MoveNext(); --- 1175,1179 ---- enumer = baz.FooToGlarch.Keys.GetEnumerator(); ! for( int i=0; i<2; i++ ) { enumer.MoveNext(); *************** *** 1202,1207 **** s.Disconnect(); ! //TODO: add test for deserialization of ISession here! s.Close(); } --- 1202,1281 ---- s.Disconnect(); ! // serialize and then deserialize the session. ! System.IO.Stream stream = new System.IO.MemoryStream(); ! System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); ! formatter.Serialize(stream, s); ! stream.Position = 0; ! s = (ISession)formatter.Deserialize(stream); ! stream.Close(); ! ! s.Reconnect(); ! baz = (Baz)s.Load( typeof(Baz), baz.Code ); ! s.Delete(baz); ! s.Delete(baz.TopGlarchez['G']); ! s.Delete(baz.TopGlarchez['H']); ! ! IDbCommand cmd = s.Connection.CreateCommand(); ! cmd.CommandText = "update " + dialect.QuoteForTableName("glarchez") + " set baz_map_id=null where baz_map_index='a'"; ! int rows = cmd.ExecuteNonQuery(); ! Assert.AreEqual( 1, rows ); ! Assert.AreEqual( 1, s.Delete("from bar in class NHibernate.DomainModel.Bar") ); ! FooProxy[] arr = baz.FooArray; ! Assert.AreEqual( 4, arr.Length ); ! Assert.AreEqual( foo.Key, arr[1].Key ); ! for(int i=0; i<arr.Length; i++) ! { ! if(arr[i]!=null) ! { ! s.Delete(arr[i]); ! } ! } ! ! //TODO: once proxies is implemented get rid of the try-catch and notFound ! bool notFound = false; ! try ! { ! s.Load( typeof(Qux), (long)666 ); //nonexistent ! } ! catch(ObjectNotFoundException onfe) ! { ! notFound = true; ! Assert.IsNotNull(onfe, "should not find a Qux with id of 666 when Proxies are not implemented."); ! } ! Assert.IsTrue( ! notFound, ! "without proxies working - an ObjectNotFoundException should have been thrown. " + ! "If Proxies are implemented then you need to change this code" ! ); + Assert.AreEqual( 1, s.Delete("from g in class Glarch") ); + s.Flush(); + s.Disconnect(); + + // serialize and then deserialize the session. + stream = new System.IO.MemoryStream(); + formatter.Serialize( stream, s ); + stream.Position = 0; + s = (ISession)formatter.Deserialize(stream); + stream.Close(); + + //TODO: once proxies is implemented get rid of the try-catch and notFound + notFound = false; + try + { + s.Load( typeof(Qux), (long)666 ) ; //nonexistent + } + catch(HibernateException he) + { + notFound = true; + Assert.IsNotNull( he, "should have a session disconnected error when finding a Qux with id of 666 and Proxies are not implemented."); + } + Assert.IsTrue( + notFound, + "without proxies working - an ADOException/HibernateException should have been thrown. " + + "If Proxies are implemented then you need to change this code because the ISession does " + + "not need to be connected to the db when building a Proxy." + ); + s.Close(); } |