From: Michael D. <mik...@us...> - 2004-06-28 19:14:07
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14782/NHibernate.Test Modified Files: FooBarTest.cs Log Message: Implemented more test. Index: FooBarTest.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/FooBarTest.cs,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** FooBarTest.cs 25 Jun 2004 20:46:28 -0000 1.28 --- FooBarTest.cs 28 Jun 2004 19:13:56 -0000 1.29 *************** *** 302,306 **** System.Text.Encoding encoding = new System.Text.UnicodeEncoding(); - // TODO: not sure about this here... byte[] bytes = encoding.GetBytes("ffo"); l2.Add(bytes); --- 302,305 ---- *************** *** 351,354 **** --- 350,354 ---- public void ForceOuterJoin() { + } *************** *** 376,382 **** [Test] - [Ignore("Test not written yet.")] public void OneToOneGenerator() { } --- 376,430 ---- [Test] public void OneToOneGenerator() { + ISession s = sessions.OpenSession(); + X x = new X(); + Y y = new Y(); + x.Y = y; + y.TheX = x; + + object yId = s.Save(y); + object xId = s.Save(x); + + Assert.AreEqual( yId, xId); + s.Flush(); + + Assert.IsTrue( s.Contains(y) && s.Contains(x) ); + s.Close(); + + Assert.AreEqual( x.Id, y.Id); + + + s = sessions.OpenSession(); + x = new X(); + y = new Y(); + + x.Y = y; + y.TheX = x; + + s.Save(y); + s.Flush(); + + Assert.IsTrue( s.Contains(y) && s.Contains(x) ); + s.Close(); + + Assert.AreEqual( x.Id, y.Id); + + + s = sessions.OpenSession(); + x = new X(); + y = new Y(); + x.Y = y; + y.TheX = x; + xId = s.Save(x); + + Assert.AreEqual(xId, y.Id); + Assert.AreEqual(xId, x.Id); + s.Flush(); + + Assert.IsTrue( s.Contains(y) && s.Contains(x) ); + s.Delete("from X x"); + s.Flush(); + s.Close(); } *************** *** 394,406 **** [Test] - [Ignore("Test not written yet.")] public void SaveAddDelete() { } [Test] ! [Ignore("Test not written yet.")] public void NamedParams() { } --- 442,484 ---- [Test] public void SaveAddDelete() { + ISession s = sessions.OpenSession(); + Baz baz = new Baz(); + IDictionary bars = new Hashtable(); + baz.CascadingBars = bars; + s.Save(baz); + s.Flush(); + + baz.CascadingBars.Add( new Bar(), new object() ); + s.Delete(baz); + s.Flush(); + s.Close(); + } [Test] ! [Ignore("Fails because Proxies not written yet.")] public void NamedParams() { + Bar bar = new Bar(); + Bar bar2 = new Bar(); + bar.Name = "Bar"; + bar2.Name = "Bar Two"; + Baz baz = new Baz(); + baz.CascadingBars = new Hashtable(); + baz.CascadingBars.Add( bar, new object() ); + bar.Baz = baz; + + ISession s = sessions.OpenSession(); + s.Save(baz); + 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 ); + + } *************** *** 412,418 **** [Test] ! [Ignore("Test not written yet.")] public void FindByCriteria() { } --- 490,572 ---- [Test] ! //[Ignore("Test not written yet.")] public void FindByCriteria() { + ISession s = sessions.OpenSession(); + Foo f = new Foo(); + s.Save(f); + s.Flush(); + + //TODO: need to add PropertyExpressions to Expression namespace. + IList list = s.CreateCriteria(typeof(Foo)) + .Add( Expression.Expression.Eq( "integer", f.integer ) ) + //.Add( Expression.Expression.EqProperty("integer", "integer") ) + .Add( Expression.Expression.Like( "string", f.@string) ) + .Add( Expression.Expression.In("boolean", new bool[] {f.boolean, f.boolean} ) ) + .SetFetchMode("foo", FetchMode.Eager) + .SetFetchMode("baz", FetchMode.Lazy) + .List(); + + Assert.IsTrue( list.Count==1 && list[0]==f ); + + list = s.CreateCriteria( typeof(Foo) ).Add( + Expression.Expression.Disjunction() + .Add( Expression.Expression.Eq( "integer", f.integer ) ) + .Add( Expression.Expression.Like( "string", f.@string ) ) + .Add( Expression.Expression.Eq( "boolean", f.boolean ) ) + ) + .Add( Expression.Expression.IsNotNull("boolean") ) + .List(); + + Assert.IsTrue( list.Count==1 && list[0]==f ); + + Expression.Expression andExpression; + Expression.Expression orExpression; + + andExpression = Expression.Expression.And( Expression.Expression.Eq( "integer", f.integer ), Expression.Expression.Like( "string", f.@string ) ); + orExpression = Expression.Expression.Or( andExpression, Expression.Expression.Eq( "boolean", f.boolean ) ); + + list = s.CreateCriteria(typeof(Foo)) + .Add( orExpression ) + .List(); + + Assert.IsTrue( list.Count==1 && list[0]==f ); + + + list = s.CreateCriteria(typeof(Foo)) + .SetMaxResults(5) + .AddOrder(Expression.Order.Asc("Date")) + .List(); + + Assert.IsTrue(list.Count==1 && list[0]==f); + + list = s.CreateCriteria(typeof(Foo)).SetMaxResults(0).List(); + Assert.AreEqual(0, list.Count); + + list = s.CreateCriteria(typeof(Foo)) + .SetFirstResult(1) + .AddOrder( Expression.Order.Asc("Date") ) + .AddOrder( Expression.Order.Desc("String") ) + .List(); + + Assert.AreEqual(0, list.Count); + + f.foo = new Foo(); + s.Save(f.foo); + s.Flush(); + s.Close(); + + //TODO: some HSQLDialect specific code here + //TODO: resume here + // s = sessions.OpenSession(); + // list = s.CreateCriteria(Foo) + // .Add( Expression.Expression.Eq( "integer", f.integer ) ) + // .Add( Expression.Expression.Like( "string", f.@string ) ) + // .Add( Expression.Expression.In( "boolean", new bool[] { f.boolean, f.boolean } ) ) + // .Add( Expression.Expression.IsNotNull("foo") ); + + + + } |