From: Michael D. <mik...@us...> - 2004-10-04 01:43:59
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30348/NHibernate.Test Modified Files: Tag: alpha_avalon-proxy FooBarTest.cs Log Message: implemented some of the test that were being ignored because proxy of interfaces was not implemented. Index: FooBarTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/FooBarTest.cs,v retrieving revision 1.67.2.1 retrieving revision 1.67.2.2 diff -C2 -d -r1.67.2.1 -r1.67.2.2 *** FooBarTest.cs 27 Sep 2004 03:41:45 -0000 1.67.2.1 --- FooBarTest.cs 4 Oct 2004 01:42:46 -0000 1.67.2.2 *************** *** 348,355 **** [Test] - [Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void ForceOuterJoin() { ! } --- 348,384 ---- [Test] public void ForceOuterJoin() { ! if( ((Engine.ISessionFactoryImplementor)sessions).EnableJoinedFetch==false ) ! { ! // don't bother to run the test if we can't test it ! return; ! } ! ! ISession s = sessions.OpenSession(); ! Glarch g = new Glarch(); ! FooComponent fc = new FooComponent(); ! fc.Glarch = g; ! FooProxy f = new Foo(); ! FooProxy f2 = new Foo(); ! f.Component = fc; ! f.TheFoo = f2; ! s.Save( f2 ); ! object id = s.Save( f ); ! object gid = s.GetIdentifier( f.Component.Glarch ); ! s.Flush(); ! s.Close(); ! ! s = sessions.OpenSession(); ! f = (FooProxy)s.Load( typeof(Foo), id ); ! Assert.IsFalse( NHibernate.IsInitialized( f ) ); ! Assert.IsTrue( NHibernate.IsInitialized( f.Component.Glarch ) ); //outer-join="true" ! Assert.IsFalse( NHibernate.IsInitialized( f.TheFoo ) ); //outer-join="auto" ! Assert.AreEqual( gid, s.GetIdentifier( f.Component.Glarch ) ); ! s.Delete( f ); ! s.Delete( f.TheFoo ); ! s.Flush(); ! s.Close(); ! } *************** *** 507,511 **** [Test] - [Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void NamedParams() { --- 536,539 ---- *************** *** 523,531 **** s.Save(bar2); - // TODO: at this point it fails because of SessionImpl.ProxyFor IList list = s.Find("from Bar bar left join bar.Baz baz left join baz.CascadingBars b where bar.Name like 'Bar %'"); object row = list[0]; Assert.IsTrue( row is object[] && ( (object[])row).Length==3 ); } --- 551,597 ---- s.Save(bar2); IList list = s.Find("from Bar bar left join bar.Baz baz left join baz.CascadingBars b where bar.Name like 'Bar %'"); object row = list[0]; Assert.IsTrue( row is object[] && ( (object[])row).Length==3 ); + IQuery q = s.CreateQuery( + "select bar, b " + + "from Bar bar " + + "left join bar.Baz baz left join baz.CascadingBars b " + + "where (bar.Name in (:nameList) or bar.Name in (:nameList)) and bar.String = :stringVal" ); + + IList nameList = new ArrayList(); + nameList.Add( "bar" ); + nameList.Add( "Bar" ); + nameList.Add( "Bar Two" ); + q.SetParameterList( "nameList", nameList ); + q.SetParameter( "stringVal", "a string" ); + list = q.List(); + // a check for SAPDialect here + Assert.AreEqual( 2, list.Count ); + + q = s.CreateQuery( + "select bar, b " + + "from Bar bar " + + "inner join bar.Baz baz inner join baz.CascadingBars b " + + "where bar.Name like 'bar%'" ); + list = q.List(); + Assert.AreEqual( 1, list.Count ); + + q = s.CreateQuery( + "select bar, b " + + "from Bar bar " + + "left join bar.Baz baz left join baz.CascadingBars b " + + "where bar.Name like :name and b.Name like :name" ); + + // add a check for HSQLDialect + q.SetString( "name", "Bar%" ); + list = q.List(); + Assert.AreEqual( 1, list.Count ); + + s.Delete( baz ); + s.Delete( bar2 ); + s.Flush(); + s.Close(); } *************** *** 1474,1478 **** [Test] - //[Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void Load() { --- 1540,1543 ---- *************** *** 2702,2708 **** [Test] - [Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void ProxyArray() { } --- 2767,2819 ---- [Test] public void ProxyArray() { + ISession s = sessions.OpenSession(); + GlarchProxy g = new Glarch(); + Glarch g1 = new Glarch(); + Glarch g2 = new Glarch(); + g.ProxyArray = new GlarchProxy[] { g1, g2 }; + Glarch g3 = new Glarch(); + s.Save( g3 ); + g2.ProxyArray = new GlarchProxy[] { null, g3, g }; + + object emptyObject = new object(); + IDictionary hashset = new Hashtable(); + hashset.Add( g1, emptyObject ); + hashset.Add( g2, emptyObject ); + g.ProxySet = hashset; + s.Save( g ); + s.Save( g1 ); + s.Save( g2 ); + object id = s.GetIdentifier( g ); + s.Flush(); + s.Close(); + + s = sessions.OpenSession(); + g = (GlarchProxy)s.Load( typeof(Glarch), id ); + Assert.AreEqual( 2, g.ProxyArray.Length, "array of proxies" ); + Assert.IsNotNull( g.ProxyArray[0], "array of proxies" ); + Assert.IsNull( g.ProxyArray[1].ProxyArray[0], "deferred load test" ); + Assert.AreEqual( g, g.ProxyArray[1].ProxyArray[2], "deferred load test" ); + Assert.AreEqual( 2, g.ProxySet.Count, "set of proxies" ); + + IEnumerator enumer = s.Enumerable( "from g in class NHibernate.DomainModel.Glarch" ).GetEnumerator(); + while( enumer.MoveNext() ) + { + s.Delete( enumer.Current ); + } + + s.Flush(); + 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.Close(); } *************** *** 2989,2993 **** [Test] - [Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void LoadAfterDelete() { --- 3100,3103 ---- *************** *** 3016,3024 **** bool somevalue = ( (FooProxy)s.Load( typeof(Foo), id )).Boolean; } - // this won't work until Proxies are implemented because now it throws an - // ObjectNotFoundException catch(LazyInitializationException lie) { ! Assert.IsNotNull(lie); //getting ride of 'lie' is never used compile warning err = true; } --- 3126,3132 ---- bool somevalue = ( (FooProxy)s.Load( typeof(Foo), id )).Boolean; } catch(LazyInitializationException lie) { ! Assert.IsNotNull( lie ); //getting ride of 'lie' is never used compile warning err = true; } *************** *** 3252,3273 **** [Test] - [Ignore("Proxies Required - http://jira.nhibernate.org:8080/browse/NH-41")] public void ProxiesInCollections() { ! } ! [Test] ! [Ignore("Test not written yet.")] ! public void Service() ! { } [Test] [Ignore("Test not written yet.")] ! public void PSCache() { } - } } --- 3360,3431 ---- [Test] public void ProxiesInCollections() { ! ISession s = sessions.OpenSession(); ! Baz baz = new Baz(); ! Bar bar = new Bar(); ! Bar bar2 = new Bar(); ! s.Save( bar ); ! object bar2id = s.Save( bar2 ); ! baz.FooArray = new Foo[] { bar, bar2 }; ! object emptyObject = new object(); ! IDictionary hashset = new Hashtable(); ! bar = new Bar(); ! s.Save( bar ); ! hashset.Add( bar, emptyObject ); ! baz.FooSet = hashset; ! hashset = new Hashtable(); ! hashset.Add( new Bar(), emptyObject ); ! hashset.Add( new Bar(), emptyObject ); ! baz.CascadingBars = hashset; ! ArrayList list = new ArrayList(); ! list.Add( new Foo() ); ! baz.FooBag = list; ! object id = s.Save( baz ); ! IEnumerator enumer = baz.CascadingBars.Keys.GetEnumerator(); ! enumer.MoveNext(); ! object bid = ((Bar)enumer.Current).Key; ! s.Flush(); ! s.Close(); ! ! s = sessions.OpenSession(); ! BarProxy barprox = (BarProxy)s.Load( typeof(Bar), bid ); ! BarProxy bar2prox = (BarProxy)s.Load( typeof(Bar), bar2id ); ! Assert.IsTrue( bar2prox is Proxy.INHibernateProxy ); ! Assert.IsTrue( barprox is Proxy.INHibernateProxy ); ! baz = (Baz)s.Load( typeof(Baz), id ); ! enumer = baz.CascadingBars.Keys.GetEnumerator(); ! enumer.MoveNext(); ! BarProxy b1 = (BarProxy)enumer.Current; ! enumer.MoveNext(); ! BarProxy b2 = (BarProxy)enumer.Current; ! Assert.IsTrue( ! ( b1==barprox && !(b2 is Proxy.INHibernateProxy) ) ! || ( b2==barprox && !(b1 is Proxy.INHibernateProxy) ) ); //one-to-many ! Assert.IsTrue( baz.FooArray[0] is Proxy.INHibernateProxy ); //many-to-many ! Assert.AreEqual( bar2prox, baz.FooArray[1] ); ! if( ((Engine.ISessionFactoryImplementor)sessions).EnableJoinedFetch ) ! { ! enumer = baz.FooBag.GetEnumerator(); ! enumer.MoveNext(); ! Assert.IsFalse( enumer.Current is Proxy.INHibernateProxy ); // many-to-many outer-join="true" ! } ! ! enumer = baz.FooSet.Keys.GetEnumerator(); ! enumer.MoveNext(); ! Assert.IsFalse( enumer.Current is Proxy.INHibernateProxy ); //one-to-many ! s.Delete( "from o in class Baz" ); ! s.Delete( "from o in class Foo" ); ! s.Flush(); ! s.Close(); } [Test] [Ignore("Test not written yet.")] ! public void Service() { } } } |