From: Michael D. <mik...@us...> - 2004-06-11 20:09:38
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11800/NHSpecificTest Modified Files: ClassWithCompositeIdFixture.cs Added Files: UserTypeFixture.cs Log Message: Added a quick test for UserTypes to save an Int32 as a null to the db. Added a quick test for using ICriteria on a CompositeId Index: ClassWithCompositeIdFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest/ClassWithCompositeIdFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ClassWithCompositeIdFixture.cs 9 Jun 2004 01:06:22 -0000 1.1 --- ClassWithCompositeIdFixture.cs 11 Jun 2004 20:09:30 -0000 1.2 *************** *** 149,152 **** --- 149,180 ---- } + [Test] + public void Criteria() + { + CompositeId id = new CompositeId("stringKey", 3, firstDateTime); + ClassWithCompositeId cId = new ClassWithCompositeId(); + cId.Id = id; + cId.OneProperty = 5; + + // add the new instance to the session so I have something to get results + // back for + ISession s = sessions.OpenSession(); + s.Save(cId); + s.Flush(); + s.Close(); + + s = sessions.OpenSession(); + ICriteria c = s.CreateCriteria(typeof(ClassWithCompositeId)); + c.Add( Expression.Expression.Eq("Id", id) ); + + // right now just want to see if the Criteria is valid + IList results = c.List(); + + Assert.AreEqual(1, results.Count); + + s.Close(); + } + + } } --- NEW FILE: UserTypeFixture.cs --- using System; using System.Data; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Summary description for UserTypeFixture. /// </summary> [TestFixture] public class UserTypeFixture : TestCase { [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.ClassWithNullColumns.hbm.xml"}, true ); } /// <summary> /// Does a quick test to make sure that a Property specified with a NullInt32UserType /// persist to the db as a null. /// </summary> [Test] public void InsertNull() { ISession s = sessions.OpenSession(); ClassWithNullColumns userTypeClass = new ClassWithNullColumns(); userTypeClass.Id = 5; userTypeClass.FirstInt32 = 4; userTypeClass.SecondInt32 = 0; // with the user type should set value to null s.Save(userTypeClass); s.Flush(); s.Close(); // manually read from the db Connection.IConnectionProvider provider = Connection.ConnectionProviderFactory.NewConnectionProvider(cfg.Properties); IDbConnection conn = provider.GetConnection(); IDbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = "select * from usertype"; IDataReader reader = cmd.ExecuteReader(); while(reader.Read()) { Assert.AreEqual(5, reader[0]); Assert.AreEqual(4, reader[1]); Assert.AreEqual(DBNull.Value, reader[2]); break; } conn.Close(); } } } |