From: Michael D. <mik...@us...> - 2004-04-14 18:09:52
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate.Test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28879 Modified Files: BasicTypes.cs Log Message: Added test for <bag> mapping. Index: BasicTypes.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate.Test/BasicTypes.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BasicTypes.cs 22 Mar 2004 04:35:36 -0000 1.5 --- BasicTypes.cs 14 Apr 2004 18:09:41 -0000 1.6 *************** *** 45,48 **** --- 45,49 ---- 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"; *************** *** 629,632 **** --- 630,718 ---- [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() { *************** *** 794,802 **** 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.StringList, actual.StringList); ObjectAssertion.AssertEquals(expected.StringMap, actual.StringMap, true); --- 880,889 ---- 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); ObjectAssertion.AssertEquals(expected.StringList, actual.StringList); ObjectAssertion.AssertEquals(expected.StringMap, actual.StringMap, true); *************** *** 838,845 **** 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 stringList = new ArrayList(5); stringList.Add("new string zero"); --- 925,939 ---- 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"); |