|
From: Michael D. <mik...@us...> - 2004-06-09 01:06:38
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/NHSpecificTest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23288/NHSpecificTest Added Files: BasicClassFixture.cs ClassWithCompositeIdFixture.cs JoinedSubclassFixture.cs MapFixture.cs NH47Fixture.cs NodeFixture.cs SimpleComponentFixture.cs SubclassFixture.cs UnsavedValueFixture.cs Log Message: Moved the new Test Fixtures I made to get NHibernate testing up and going to their own namespace because there was some name conflicts with h2.0.3 classes. --- NEW FILE: BasicClassFixture.cs --- using System; using System.Collections; using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { [TestFixture] public class BasicClassFixture : TestCase { [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.BasicClass.hbm.xml"}, true ); } [Test] public void TestCRUD() { int maxIndex = 22; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // make sure the previous insert went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); Assertion.AssertNotNull(bc[index]); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].Int32Array[1] = 15; bc[index].StringBag[0] = "Replaced Spot 0"; bc[index].StringArray[2] = "Replaced Spot 2"; bc[index].StringList[0] = "Replaced Spot 0"; bc[index].StringMap["keyZero"] = "Replaced Key 0"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].BooleanProperty = false; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // update the Binary property to make sure it picks up that it is dirty BinaryFormatter bf = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); bf.Serialize(stream, 4); bc[index].BinaryProperty = stream.ToArray(); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].ByteProperty = Byte.MinValue; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].CharacterProperty = 'b'; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // update a property to make sure it picks up that it is dirty s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].ClassProperty = typeof(System.String); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // 12 = french bc[index].CultureInfoProperty = new System.Globalization.CultureInfo(12); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].DateTimeProperty = DateTime.Parse("2004-02-15 08:00:00 PM"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].DecimalProperty = 5.55555M; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].DoubleProperty = 6458946; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].Int16Property = Int16.MinValue; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].Int32Property = Int32.MinValue; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].Int64Property = Int64.MinValue; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].SerializableProperty = new SerializableClass(); bc[index].SerializableProperty._classId = 1; bc[index].SerializableProperty._classString = "one string"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].SingleProperty = bc[index].SingleProperty * -1; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringProperty = "new string property"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].TicksProperty = DateTime.Now; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].TrueFalseProperty = false; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // make sure the previous updates went through s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].YesNoProperty = false; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY DELETE AssertDelete(id); } [Test] public void TestArrayCRUD() { int maxIndex = 4; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the array so it is updated - should not be recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringArray[0] = "modified string 0"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // change the array to a new array so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringArray = new string[] {"string one", "string two"}; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } [Test] public void TestPrimitiveArrayCRUD() { int maxIndex = 4; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the array so it is updated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); for(int i = 0; i < bc[index].Int32Array.Length; i++) { bc[index].Int32Array[i] = i+1; } s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // modify the array to a new array so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].Int32Array = new int[] {1,2,3,4,5,6}; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } [Test] public void TestMapCRUD() { int maxIndex = 4; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the array so it is updated - should not be recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and update another bc[index].StringMap.Remove("keyOne"); bc[index].StringMap["keyTwo"] = "modified string two"; bc[index].StringMap["keyThree"] = "added key three"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // change the List to a new List so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringMap = new Hashtable(); bc[index].StringMap.Add("keyZero", "new list zero"); bc[index].StringMap.Add("keyOne", "new list one"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } [Test] public void TestSetCRUD() { int maxIndex = 4; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the array so it is updated - should not be recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and add another bc[index].StringSet.Remove("zero"); bc[index].StringSet.Add("two", new object()); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // change the List to a new List so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringSet = new Hashtable(); bc[index].StringSet.Add("zero", new object()); bc[index].StringSet.Add("one", new object()); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } [Test] public void TestBagCRUD() { int maxIndex = 5; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the bag so it is updated - should not be recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and update another bc[index].StringBag.RemoveAt(bc[index].StringBag.Count-1); bc[index].StringBag[1] = "modified string 1"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // add an item to the list s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and update another bc[index].StringBag.Add("inserted into the bag"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // change the List to a new List so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringBag = new ArrayList(); bc[index].StringBag.Add("new bag zero"); bc[index].StringBag.Add("new bag one"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } [Test] public void TestListCRUD() { int maxIndex = 5; ISession[] s = new ISession[maxIndex]; ITransaction[] t = new ITransaction[maxIndex]; BasicClass[] bc = new BasicClass[maxIndex]; int index = 0; int id = 1; bc[index] = InsertBasicClass(id); index++; // modify the array so it is updated - should not be recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and update another bc[index].StringList.RemoveAt(bc[index].StringList.Count-1); bc[index].StringList[2] = "modified string 2"; s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // add an item to the list s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // remove the last one and update another bc[index].StringList.Add("inserted into the list"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // change the List to a new List so it is recreated s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); bc[index].StringList = new ArrayList(); bc[index].StringList.Add("new list zero"); bc[index].StringList.Add("new list one"); s[index].Update(bc[index]); t[index].Commit(); s[index].Close(); index++; // VERIFY PREVIOUS UPDATE & PERFORM DELETE s[index] = sessions.OpenSession(); t[index] = s[index].BeginTransaction(); bc[index] = (BasicClass)s[index].Load(typeof(BasicClass), id); AssertPropertiesEqual(bc[index-1], bc[index]); // test the delete method s[index].Delete(bc[index]); t[index].Commit(); s[index].Close(); index++; // verify the delete went through AssertDelete(id); } internal void AssertDelete(int id) { ISession s = sessions.OpenSession(); try { BasicClass bc = (BasicClass)s.Load(typeof(BasicClass), id); } catch(ObjectNotFoundException onfe) { // I expect this to be thrown because the object no longer exists... } IList results = s.CreateCriteria(typeof(BasicClass)) .Add(Expression.Expression.Eq("Id", id)) .List(); Assertion.AssertEquals(0, results.Count); s.Close(); } internal BasicClass InsertBasicClass(int id) { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); BasicClass bc = new BasicClass(); InitializeBasicClass(id, ref bc); s.Save(bc); t.Commit(); s.Close(); return bc; } /// <summary> /// Compares the non Collection Properties of the BasicClass /// </summary> /// <param name="expected">The expected values.</param> /// <param name="actual">The Actual values.</param> /// <remarks> /// Passes to the overload with includeCollections=true /// </remarks> internal void AssertPropertiesEqual(BasicClass expected, BasicClass actual) { AssertPropertiesEqual(expected, actual, true); } /// <summary> /// Compares the non Collection Properties of the BasicClass /// </summary> /// <param name="expected">The expected values.</param> /// <param name="actual">The Actual values.</param> internal void AssertPropertiesEqual(BasicClass expected, BasicClass actual, bool includeCollections) { Assert.AreEqual(expected.Id, actual.Id, "Id"); ObjectAssertion.AssertEquals(expected.BinaryProperty, actual.BinaryProperty); Assert.AreEqual(expected.BooleanProperty, actual.BooleanProperty, "BooleanProperty"); Assert.AreEqual(expected.ByteProperty, actual.ByteProperty, "ByteProperty"); Assert.AreEqual(expected.CharacterProperty, actual.CharacterProperty, "CharacterProperty"); Assert.AreEqual(expected.ClassProperty, actual.ClassProperty, "ClassProperty"); Assert.AreEqual(expected.CultureInfoProperty, actual.CultureInfoProperty, "CultureInfoProperty"); Assert.AreEqual(expected.DateTimeProperty, actual.DateTimeProperty, "DateTimeProperty"); Assert.AreEqual(expected.DecimalProperty, actual.DecimalProperty, "DecimalProperty using Assert should be AreEqual"); Assertion.Assert("DecimalProperty", expected.DecimalProperty.Equals(actual.DecimalProperty)); Assert.AreEqual(expected.DoubleProperty, actual.DoubleProperty, 0, "DoubleProperty"); Assert.AreEqual(expected.Int16Property, actual.Int16Property, "Int16Property"); Assert.AreEqual(expected.Int32Property, actual.Int32Property, "Int32Property"); Assert.AreEqual(expected.Int64Property, actual.Int64Property, "Int64Property"); Assert.AreEqual(expected.SerializableProperty, actual.SerializableProperty, "SerializableProperty"); Assert.AreEqual(expected.SingleProperty, actual.SingleProperty, 0, "SingleProperty"); Assert.AreEqual(expected.StringProperty, actual.StringProperty, "StringProperty"); Assert.AreEqual(expected.TicksProperty, actual.TicksProperty, "TicksProperty"); Assert.AreEqual(expected.TrueFalseProperty, actual.TrueFalseProperty, "TrueFalseProperty"); Assert.AreEqual(expected.YesNoProperty, actual.YesNoProperty, "YesNoProperty"); if(includeCollections) { ObjectAssertion.AssertEquals(expected.StringArray, actual.StringArray); ObjectAssertion.AssertEquals(expected.Int32Array, actual.Int32Array); ObjectAssertion.AssertEquals(expected.StringBag, actual.StringBag, false); ObjectAssertion.AssertEquals(expected.StringList, actual.StringList); ObjectAssertion.AssertEquals(expected.StringMap, actual.StringMap, true); ObjectAssertion.AssertEquals(expected.StringSet, actual.StringSet, false); } } private void InitializeBasicClass(int id, ref BasicClass basicClass) { basicClass.Id = id; BinaryFormatter bf = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); bf.Serialize(stream, 5); basicClass.BinaryProperty = stream.ToArray(); basicClass.BooleanProperty = true; basicClass.ByteProperty = Byte.MaxValue; basicClass.CharacterProperty = 'a'; basicClass.ClassProperty = typeof(object); basicClass.CultureInfoProperty = System.Globalization.CultureInfo.CurrentCulture; basicClass.DateTimeProperty = DateTime.Parse("2003-12-01 10:45:21 AM"); basicClass.DecimalProperty = 5.64351M; basicClass.DoubleProperty = 456343; basicClass.Int16Property = Int16.MaxValue; basicClass.Int32Property = Int32.MaxValue; basicClass.Int64Property = Int64.MaxValue; basicClass.SerializableProperty = new SerializableClass(); basicClass.SerializableProperty._classId = 2; basicClass.SerializableProperty._classString = "string"; // more MySql problems - it returns 3.40282E38 // instead of 3.402823E+38 which is Single.MaxValue basicClass.SingleProperty = 3.5F; //Single.MaxValue; basicClass.StringProperty = "string property"; basicClass.TicksProperty = DateTime.Now; basicClass.TrueFalseProperty = true; basicClass.YesNoProperty = true; basicClass.StringArray = new string[] {"3 string", "2 string", "1 string"}; basicClass.Int32Array = new int[] {5,4,3,2,1}; IList stringBag = new ArrayList(3); stringBag.Add("string 0"); stringBag.Add("string 1"); stringBag.Add("string 2"); basicClass.StringBag = stringBag; IList stringList = new ArrayList(5); stringList.Add("new string zero"); stringList.Add("new string one"); stringList.Add("new string two"); stringList.Add("new string three"); stringList.Add("new string four"); basicClass.StringList = stringList; IDictionary stringMap = new Hashtable(); stringMap.Add("keyOne", "string one"); stringMap.Add("keyZero", "string zero"); stringMap.Add("keyTwo", "string two"); basicClass.StringMap = stringMap; basicClass.AddToStringSet("zero"); basicClass.AddToStringSet("one"); basicClass.AddToStringSet("zero"); } } } --- NEW FILE: SubclassFixture.cs --- using System; using System.Collections; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { [TestFixture] public class SubclassFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); [SetUp] public void SetUp() { //log4net.Config.DOMConfigurator.Configure(); ExportSchema( new string[] { "NHSpecific.Subclass.hbm.xml" } ); } [Test] public void TestCRUD() { // test the Save ISession s1 = sessions.OpenSession(); ITransaction t1 = s1.BeginTransaction(); JoinedSubclassOne one1 = new JoinedSubclassOne(); one1.Id = 2; one1.TestDateTime = new System.DateTime(2003, 10, 17); one1.TestString = "the test one string"; one1.TestLong = 6; one1.OneTestLong = 1; s1.Save(one1); JoinedSubclassBase base1 = new JoinedSubclassBase(); base1.Id = 1; base1.TestDateTime = new System.DateTime(2003, 10, 17); base1.TestString = "the test string"; base1.TestLong = 5; s1.Save(base1); t1.Commit(); s1.Close(); // lets verify the correct classes were saved ISession s2 = sessions.OpenSession(); ITransaction t2 = s2.BeginTransaction(); // perform a load based on the base class JoinedSubclassBase base2 = (JoinedSubclassBase)s2.Load(typeof(JoinedSubclassBase), 1); JoinedSubclassBase oneBase2 = (JoinedSubclassBase)s2.Load(typeof(JoinedSubclassBase), 2); // do some quick checks to make sure s2 loaded an object with the same data as s2 saved. ObjectAssertion.AssertPropertiesEqual(base1, base2); // the object with id=2 was loaded using the base class - lets make sure it actually loaded // the sublcass JoinedSubclassOne one2 = oneBase2 as JoinedSubclassOne; Assertion.AssertNotNull(one2); // lets update the objects base2.TestString = "Did it get updated"; // update the properties from the subclass and base class one2.TestString = "Updated JoinedSubclassOne String"; one2.OneTestLong = 21; // save it through the base class reference and make sure that the // subclass properties get updated. s2.Update(base2); s2.Update(oneBase2); t2.Commit(); s2.Close(); // lets test the Criteria interface for subclassing ISession s3 = sessions.OpenSession(); ITransaction t3 = s3.BeginTransaction(); IList results3 = s3.CreateCriteria(typeof(JoinedSubclassBase)) .Add(Expression.Expression.In("TestString", new string[] {"Did it get updated", "Updated JoinedSubclassOne String" })) .List(); Assertion.AssertEquals(2, results3.Count); JoinedSubclassBase base3 = null; JoinedSubclassOne one3 = null; foreach(JoinedSubclassBase obj in results3) { if(obj is JoinedSubclassOne) one3 = (JoinedSubclassOne)obj; else base3 = obj; } // verify the properties got updated ObjectAssertion.AssertPropertiesEqual(base2, base3); ObjectAssertion.AssertPropertiesEqual(one2, one3); s3.Delete(base3); s3.Delete(one3); t3.Commit(); s3.Close(); } } } --- NEW FILE: SimpleComponentFixture.cs --- using System; using System.Data; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { [TestFixture] public class SimpleCompenentFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.SimpleComponent.hbm.xml"} ); } [Test] public void TestLoad() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); TestInsert(); SimpleComponent simpleComp = (SimpleComponent)s.Load(typeof(SimpleComponent), 10); Assertion.AssertEquals(10, simpleComp.Key); Assertion.AssertEquals("TestCreated", simpleComp.Audit.CreatedUserId); Assertion.AssertEquals("TestUpdated", simpleComp.Audit.UpdatedUserId); t.Commit(); s.Close(); } /// <summary> /// Test the ability to insert a new row with a User Assigned Key /// Right now - the only way to verify this is to watch SQL Profiler /// </summary> [Test] public void TestInsert() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); // create a new SimpleComponent simpleComp = new SimpleComponent(); simpleComp.Name = "Simple 1"; simpleComp.Address = "Street 12"; simpleComp.Date = testDateTime; simpleComp.Count = 99; simpleComp.Audit.CreatedDate = System.DateTime.Now; simpleComp.Audit.CreatedUserId = "TestCreated"; simpleComp.Audit.UpdatedDate = System.DateTime.Now; simpleComp.Audit.UpdatedUserId = "TestUpdated"; s.Save(simpleComp, 10); t.Commit(); s.Close(); } } } --- NEW FILE: JoinedSubclassFixture.cs --- using System; using System.Collections; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { [TestFixture] public class JoinedSubclassFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.JoinedSubclass.hbm.xml" } ); } /// <summary> /// Test the ability to insert a new row with a User Assigned Key /// Right now - the only way to verify this is to watch SQL Profiler /// </summary> [Test] public void TestCRUD() { int one1Id; int base1Id; // test the Save ISession s1 = sessions.OpenSession(); ITransaction t1 = s1.BeginTransaction(); JoinedSubclassOne one1 = new JoinedSubclassOne(); //one1.Id = 2; one1.TestDateTime = new System.DateTime(2003, 10, 17); one1.TestString = "the test one string"; one1.TestLong = 6; one1.OneTestLong = 1; s1.Save(one1); JoinedSubclassBase base1 = new JoinedSubclassBase(); //base1.Id = 1; base1.TestDateTime = new System.DateTime(2003, 10, 17); base1.TestString = "the test string"; base1.TestLong = 5; s1.Save(base1); t1.Commit(); s1.Close(); one1Id = one1.Id; base1Id = base1.Id; // lets verify the correct classes were saved ISession s2 = sessions.OpenSession(); ITransaction t2 = s2.BeginTransaction(); // perform a load based on the base class JoinedSubclassBase base2 = (JoinedSubclassBase)s2.Load(typeof(JoinedSubclassBase), base1Id); JoinedSubclassBase oneBase2 = (JoinedSubclassBase)s2.Load(typeof(JoinedSubclassBase), one1Id); // do some quick checks to make sure s2 loaded an object with the same data as s2 saved. ObjectAssertion.AssertPropertiesEqual(base1, base2); // the object with id=2 was loaded using the base class - lets make sure it actually loaded // the sublcass JoinedSubclassOne one2 = oneBase2 as JoinedSubclassOne; Assertion.AssertNotNull(one2); // lets update the objects base2.TestString = "Did it get updated"; // update the properties from the subclass and base class one2.TestString = "Updated JoinedSubclassOne String"; one2.OneTestLong = 21; // save it through the base class reference and make sure that the // subclass properties get updated. s2.Update(base2); s2.Update(oneBase2); t2.Commit(); s2.Close(); // lets test the Criteria interface for subclassing ISession s3 = sessions.OpenSession(); ITransaction t3 = s3.BeginTransaction(); IList results3 = s3.CreateCriteria(typeof(JoinedSubclassBase)) .Add(Expression.Expression.In("TestString", new string[] {"Did it get updated", "Updated JoinedSubclassOne String" })) .List(); Assertion.AssertEquals(2, results3.Count); JoinedSubclassBase base3 = null; JoinedSubclassOne one3 = null; foreach(JoinedSubclassBase obj in results3) { if(obj is JoinedSubclassOne) one3 = (JoinedSubclassOne)obj; else base3 = obj; } // verify the properties got updated ObjectAssertion.AssertPropertiesEqual(base2, base3); ObjectAssertion.AssertPropertiesEqual(one2, one3); s3.Delete(base3); s3.Delete(one3); t3.Commit(); s3.Close(); } } } --- NEW FILE: UnsavedValueFixture.cs --- using System; using System.Collections; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Summary description for UnsavedValueTest. /// </summary> [TestFixture] public class UnsavedValueFixture : TestCase { public static int newId = 0; [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.UnsavedType.hbm.xml"}); } [Test] public void TestCRUD() { // make a new object outside of the Session UnsavedType unsavedToSave = new UnsavedType(); unsavedToSave.TypeName = "Simple UnsavedValue"; // open the first session to SaveOrUpdate it - should be Save ISession s1 = sessions.OpenSession(); ITransaction t1 = s1.BeginTransaction(); s1.SaveOrUpdate(unsavedToSave); t1.Commit(); s1.Close(); // simple should have been inserted - generating a new key for it Assertion.Assert("Id should not be zero", unsavedToSave.Id != 0); // use the ICriteria interface to get another instance in a different // session ISession s2 = sessions.OpenSession(); ITransaction t2 = s2.BeginTransaction(); IList results2 = s2.CreateCriteria(typeof(UnsavedType)) .Add(Expression.Expression.Eq("Id", unsavedToSave.Id)) .List(); Assertion.AssertEquals("Should have found a match for the new Id", 1, results2.Count); UnsavedType unsavedToUpdate = (UnsavedType)results2[0]; // make sure it has the same Id Assertion.AssertEquals("Should have the same Id", unsavedToSave.Id, unsavedToUpdate.Id); t2.Commit(); s2.Close(); // passing it to the UI for modification unsavedToUpdate.TypeName = "ui changed it"; // create a new session for the Update ISession s3 = sessions.OpenSession(); ITransaction t3 = s3.BeginTransaction(); s3.SaveOrUpdate(unsavedToUpdate); t3.Commit(); s3.Close(); // make sure it has the same Id - if the Id has changed then that means it // was inserted. Assertion.AssertEquals("Should have the same Id", unsavedToSave.Id, unsavedToUpdate.Id); // lets get a list of all the rows in the table to make sure // that there has not been any extra inserts ISession s4 = sessions.OpenSession(); ITransaction t4 = s4.BeginTransaction(); IList results4 = s4.CreateCriteria(typeof(UnsavedType)).List(); Assertion.AssertEquals("Should only be one item", 1, results4.Count); // lets make sure the object was updated UnsavedType unsavedToDelete = (UnsavedType)results4[0]; Assertion.AssertEquals(unsavedToUpdate.TypeName, unsavedToDelete.TypeName); s4.Delete(unsavedToDelete); t4.Commit(); s4.Close(); // lets make sure the object was deleted ISession s5 = sessions.OpenSession(); try { UnsavedType unsavedNull = (UnsavedType)s5.Load(typeof(UnsavedType), unsavedToDelete.Id); Assertion.AssertNull(unsavedNull); } catch(ObjectNotFoundException onfe) { // do nothing it was expected } s5.Close(); } } } --- NEW FILE: ClassWithCompositeIdFixture.cs --- using System; using System.Collections; using System.Data; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Summary description for ClassWithCompositeIdFixture. /// </summary> [TestFixture] public class ClassWithCompositeIdFixture : TestCase { private DateTime firstDateTime = new DateTime(2003, 8, 16); private DateTime secondDateTime = new DateTime(2003, 8, 17); [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.ClassWithCompositeId.hbm.xml" } ); } /// <summary> /// Test the basic CRUD operations for a class with a Composite Identifier /// </summary> /// <remarks> /// The following items are tested in this Test Script /// <list type=""> /// <item> /// <term>Save</term> /// </item> /// <item> /// <term>Load</term> /// </item> /// <item> /// <term>Criteria</term> /// </item> /// <item> /// <term>Update</term> /// </item> /// <item> /// <term>Delete</term> /// </item> /// <item> /// <term>Criteria - No Results</term> /// </item> /// </list> /// </remarks> [Test] public void TestSimpleCRUD() { CompositeId id = new CompositeId("stringKey", 3, firstDateTime); CompositeId secondId = new CompositeId("stringKey2", 5, secondDateTime); // insert the new objects ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); ClassWithCompositeId theClass = new ClassWithCompositeId(); theClass.Id = id; theClass.OneProperty = 5; ClassWithCompositeId theSecondClass = new ClassWithCompositeId(); theSecondClass.Id = secondId; theSecondClass.OneProperty = 10; s.Save(theClass); s.Save(theSecondClass); t.Commit(); s.Close(); // verify they were inserted and test the SELECT ISession s2 = sessions.OpenSession(); ITransaction t2 = s2.BeginTransaction(); ClassWithCompositeId theClass2 = (ClassWithCompositeId)s2.Load(typeof(ClassWithCompositeId), id); IList results2 = s2.CreateCriteria(typeof(ClassWithCompositeId)) .Add(Expression.Expression.Eq("Id", secondId)) .List(); Assertion.AssertEquals(1, results2.Count); ClassWithCompositeId theSecondClass2 = (ClassWithCompositeId)results2[0]; ClassWithCompositeId theClass2Copy = (ClassWithCompositeId)s2.Load(typeof(ClassWithCompositeId), id); // verify the same results through Criteria & Load were achieved Assertion.AssertSame(theClass2, theClass2Copy); // compare them to the objects created in the first session Assertion.AssertEquals(theClass.Id, theClass2.Id); Assertion.AssertEquals(theClass.OneProperty, theClass2.OneProperty); Assertion.AssertEquals(theSecondClass.Id, theSecondClass2.Id); Assertion.AssertEquals(theSecondClass.OneProperty, theSecondClass2.OneProperty); // test the update functionallity theClass2.OneProperty = 6; theSecondClass2.OneProperty = 11; s2.Update(theClass2); s2.Update(theSecondClass2); t2.Commit(); s2.Close(); // lets verify the update went through ISession s3 = sessions.OpenSession(); ITransaction t3 = s3.BeginTransaction(); ClassWithCompositeId theClass3 = (ClassWithCompositeId)s3.Load(typeof(ClassWithCompositeId), id); ClassWithCompositeId theSecondClass3 = (ClassWithCompositeId)s3.Load(typeof(ClassWithCompositeId), secondId); // check the update properties Assertion.AssertEquals(theClass3.OneProperty, theClass2.OneProperty); Assertion.AssertEquals(theSecondClass3.OneProperty, theSecondClass2.OneProperty); // test the delete method s3.Delete(theClass3); s3.Delete(theSecondClass3); t3.Commit(); s3.Close(); // lets verify the delete went through ISession s4 = sessions.OpenSession(); try { ClassWithCompositeId theClass4 = (ClassWithCompositeId)s4.Load(typeof(ClassWithCompositeId), id); } catch(ObjectNotFoundException onfe) { // I expect this to be thrown because the object no longer exists... } IList results = s4.CreateCriteria(typeof(ClassWithCompositeId)) .Add(Expression.Expression.Eq("Id", secondId)) .List(); Assertion.AssertEquals(0, results.Count); } } } --- NEW FILE: NH47Fixture.cs --- using System; using System.Data; using System.Collections; using NHibernate; using NExp = NHibernate.Expression; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { [TestFixture] public class NH47Fxiture : TestCase { [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.UnsavedType.hbm.xml"}); } public TimeSpan BatchInsert(object[] objs) { System.TimeSpan tspan = TimeSpan.Zero; if (objs != null && objs.Length > 0) { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); int count = objs.Length; Console.WriteLine(); Console.WriteLine("Start batch insert " + count.ToString() + " objects"); DateTime startTime = DateTime.Now; for(int i = 0; i < count; ++i) { s.Save(objs[i]); } t.Commit(); s.Close(); tspan = DateTime.Now.Subtract(startTime); Console.WriteLine("Finish in " + tspan.TotalMilliseconds.ToString() + " milliseconds"); } return tspan; } [Test] [Ignore("Only run this by itself")] public void TestNH47() { int testCount = 100; object[] al = new object[testCount]; TimeSpan tspan = TimeSpan.Zero; int times = 1000; for (int i = 0; i < times; ++i) { for (int j = 0; j < testCount; ++j) { UnsavedType ut = new UnsavedType(); ut.Id = j + 1 + testCount * (i + 1); ut.TypeName = System.Guid.NewGuid().ToString(); al[j] = ut; } tspan = tspan.Add(BatchInsert(al)); } Console.WriteLine("Finish average in " + (tspan.TotalMilliseconds / times).ToString() + " milliseconds for " + times.ToString() + " times"); Console.Read(); } } } --- NEW FILE: NodeFixture.cs --- using System; using System.Collections; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Summary description for NodeFixture. /// </summary> [TestFixture] public class NodeFixture : TestCase { [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.Node.hbm.xml"}, true ); } [Test] public void InsertNodes() { Node startNode = new Node("start"); Node levelOneNode = new Node("1"); Node levelTwoFirstNode = new Node("2-1"); Node levelTwoSecondNode = new Node("2-2"); Node levelThreeNode = new Node("3"); Node endNode = new Node("end"); startNode.AddDestinationNode(levelOneNode); levelOneNode.AddDestinationNode(levelTwoFirstNode); levelOneNode.AddDestinationNode(levelTwoSecondNode); levelTwoFirstNode.AddDestinationNode(levelThreeNode); levelTwoSecondNode.AddDestinationNode(levelThreeNode); levelThreeNode.AddDestinationNode(endNode); ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); s.Save(startNode); s.Save(levelOneNode); s.Save(levelTwoFirstNode); s.Save(levelTwoSecondNode); s.Save(levelThreeNode); s.Save(endNode); s.Flush(); t.Commit(); s.Close(); // verify these nodes were actually saved and can be queried correctly. ISession s2 = sessions.OpenSession(); ITransaction t2 = s2.BeginTransaction(); Node startNode2 = (Node)s2.CreateCriteria(typeof(Node)) .Add(Expression.Expression.Eq("Id", "start")) .List()[0]; Assert.AreEqual(1, startNode2.DestinationNodes.Count, "Start Node goes to 1 Node"); Assert.AreEqual(0, startNode2.PreviousNodes.Count, "Start Node has no previous Nodes"); Assert.IsTrue(startNode2.DestinationNodes.Contains(levelOneNode), "The DestinationNodes contain the LevelOneNode"); Node levelOneNode2 = null; Node levelTwoFirstNode2 = new Node("2-1"); Node levelTwoSecondNode2 = new Node("2-2"); // only one node foreach(Node node in startNode2.DestinationNodes.Keys) { // replace the levelOneNode from previous session with the one from this Session. levelOneNode2 = node; } Assert.AreEqual(2, levelOneNode2.DestinationNodes.Count, "Level One Node goes to 2 Nodes"); Assert.AreEqual(1, levelOneNode2.PreviousNodes.Count, "The Start Node lead into Level 1"); Assert.IsTrue(levelOneNode2.DestinationNodes.Contains(levelTwoFirstNode2), "Level one goes to TwoFirst"); Assert.IsTrue(levelOneNode2.DestinationNodes.Contains(levelTwoSecondNode2), "Level one goes to TwoSecond"); Assert.IsTrue(levelOneNode2.PreviousNodes.Contains(startNode2), "Level One can be reached through Start Node"); // // TODO: get rid of this HACK that was used to find out what was causing the problem // // lets test out my theory that the problem is the "END" node being loaded during flush by just loading // // it before the flush. If it loads before the flush I don't think there will be any problems. See // // http://jira.nhibernate.org:8080/browse/NH-20 for what I think is happening... // foreach(Node node2 in levelOneNode2.DestinationNodes.Keys) // { // System.Diagnostics.Debug.WriteLine("touching node2's destinations = " + node2.DestinationNodes.Count); // foreach(Node node3 in node2.DestinationNodes.Keys) // { // System.Diagnostics.Debug.WriteLine("touching node3's destinations - " + node3.DestinationNodes.Count); // } // } //foreach t2.Commit(); s2.Close(); } } } --- NEW FILE: MapFixture.cs --- using System; using System.Data; using System.Collections; using NHibernate.DomainModel.NHSpecific; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest { /// <summary> /// Summary description for MapTest. /// </summary> [TestFixture] public class MapFixture : TestCase { private DateTime testDateTime = new DateTime(2003, 8, 16); private DateTime updateDateTime = new DateTime(2003, 8, 17); [SetUp] public void SetUp() { ExportSchema( new string[] { "NHSpecific.Parent.hbm.xml", "NHSpecific.Child.hbm.xml", "NHSpecific.SexType.hbm.xml", "NHSpecific.Team.hbm.xml" }, true); } [Test] [Ignore("Have not written the Test yet.")] public void TestDelete() { //System.Diagnostics.Debug.Write("testing some crap"); } [Test] public void TestSelect() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); TestInsert(); ICriteria chiefsCriteria = s.CreateCriteria(typeof(Team)); chiefsCriteria.Add(Expression.Expression.Eq("Name", "Chiefs")); Team chiefs = (Team)chiefsCriteria.List()[0]; IList players = chiefs.Players; Parent parentDad = (Parent)s.Load(typeof(Parent), 1); Child amyJones = (Child)s.Load(typeof(Child), 2); Child[] friends = amyJones.Friends; Child childOneRef = amyJones.FirstSibling; t.Commit(); s.Close(); } [Test] [Ignore("Code is incomplete")] public void TestInverse() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); TestInsert(); Parent bobJones = (Parent)s.CreateCriteria(typeof(Parent)) .Add(Expression.Expression.Eq("AdultName", "Bob Jones")) .List()[0]; t.Commit(); s.Close(); } [Test] public void TestSort() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); TestInsert(); Parent bobJones = (Parent)s.Load(typeof(Parent), 1); IDictionary friends = bobJones.AdultFriends; int currentId = 0; int previousId = 0; foreach(Parent friend in friends.Keys) { previousId = currentId; currentId = friend.Id; Assertion.Assert("Current should have a higher Id than previous", currentId > previousId); } t.Commit(); s.Close(); } [Test] public void TestInsert() { ISession s = sessions.OpenSession(); ITransaction t = s.BeginTransaction(); SexType male = new SexType(); SexType female = new SexType(); //male.Id = 1; male.TypeName = "Male"; //female.Id = 2; female.TypeName = "Female"; s.Save(male); s.Save(female); Parent bobJones = new Parent(); bobJones.Id = 1; bobJones.AdultName = "Bob Jones"; Parent maryJones = new Parent(); maryJones.Id = 2; maryJones.AdultName = "Mary Jones"; Parent charlieSmith = new Parent(); charlieSmith.Id = 3; charlieSmith.AdultName = "Charlie Smith"; Parent cindySmith = new Parent(); cindySmith.Id = 4; cindySmith.AdultName = "Cindy Smith"; bobJones.AddFriend(cindySmith); bobJones.AddFriend(charlieSmith); bobJones.AddFriend(maryJones); maryJones.AddFriend(cindySmith); s.Save(bobJones, bobJones.Id); s.Save(maryJones, maryJones.Id); s.Save(charlieSmith, charlieSmith.Id); s.Save(cindySmith, cindySmith.Id); Child johnnyJones = new Child(); Child amyJones = new Child(); Child brianSmith = new Child(); Child sarahSmith = new Child(); johnnyJones.Id = 1; johnnyJones.FullName = "Johnny Jones"; johnnyJones.Dad = bobJones; johnnyJones.Mom = maryJones; johnnyJones.Sex = male; johnnyJones.Friends = new Child[]{brianSmith, sarahSmith}; johnnyJones.FavoriteDate = System.DateTime.Parse("2003-08-16"); amyJones.Id = 2; amyJones.FullName = "Amy Jones"; amyJones.Dad = bobJones; amyJones.Mom = maryJones; amyJones.Sex = female; amyJones.FirstSibling = johnnyJones; amyJones.Friends = new Child[]{johnnyJones, sarahSmith}; brianSmith.Id = 11; brianSmith.FullName = "Brian Smith"; brianSmith.Dad = charlieSmith; brianSmith.Mom = cindySmith; brianSmith.Sex = male; brianSmith.Friends = new Child[]{johnnyJones, amyJones, sarahSmith}; sarahSmith.Id = 12; sarahSmith.FullName = "Sarah Smith"; sarahSmith.Dad = charlieSmith; sarahSmith.Mom = cindySmith; sarahSmith.Sex = female; sarahSmith.Friends = new Child[]{brianSmith}; Team royals = new Team(); royals.Name = "Royals"; Team chiefs = new Team(); chiefs.Name = "Chiefs"; royals.Players = new ArrayList(); royals.Players.Add(amyJones); royals.Players.Add(brianSmith); chiefs.Players = new ArrayList(); chiefs.Players.Add(johnnyJones); chiefs.Players.Add(sarahSmith); s.Save(johnnyJones, johnnyJones.Id); s.Save(amyJones, amyJones.Id); s.Save(brianSmith, brianSmith.Id); s.Save(sarahSmith, sarahSmith.Id); s.Save(royals); s.Save(chiefs); t.Commit(); s.Close(); } } } |