From: Dan M. <dan...@us...> - 2005-01-02 09:41:22
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1805/Nunit/InheritedClasses Modified Files: SuperClassTests.vb tblAtoKClasses.vb Log Message: Add test to check if multiple retrive creteria of oneToMany collections does not duplicate records. Fix the problem in retriveAssociation() in CPersistentBroker.vb. Checks whether the object exist in the collection before adding it. Index: tblAtoKClasses.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/tblAtoKClasses.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- tblAtoKClasses.vb 21 Dec 2004 22:00:01 -0000 1.4 +++ tblAtoKClasses.vb 2 Jan 2005 09:41:10 -0000 1.5 @@ -112,12 +112,16 @@ Inherits CPersistentObject Public Sub New() + _nCol = New CPersistentCollection + _nCol.ContainerObject = Me + Me.SetDirtyFlag() End Sub Public _id As Integer = 0 Public _text As String = String.Empty Public _a As A = Nothing Public _aOID As String = Nothing + Public _nCol As CPersistentCollection Public Property Id() As Integer Get @@ -185,6 +189,21 @@ End Set End Property + Public Property NCol() As CPersistentCollection + Get + Return Me._nCol + End Get + Set(ByVal Value As CPersistentCollection) + If Me._nCol.Equals(Value) Then + Me._nCol = Value + For Each _n As N In Me._nCol + _n.B = Me + Next + SetDirtyFlag() + End If + End Set + End Property + Public Overloads Overrides Function getNewObject() As CPersistentObject Return New B End Function @@ -663,4 +682,75 @@ End Function End Class + Public Class N + Inherits CPersistentObject + + Public Sub New() + End Sub + Private _i As Integer = 0 + Private _b As B = Nothing + Private _bOID As String = Nothing + + Public Property I() As Integer + Get + Return Me._i + End Get + Set(ByVal Value As Integer) + If Not (Me._i = Value) Then + Me._i = Value + Me.SetDirtyFlag() + End If + End Set + End Property + + Public Property B() As B + Get + Return Me._b + End Get + Set(ByVal Value As B) + If Me._b Is Nothing AndAlso Not (Value Is Nothing) Then + Me._b = Value + Me._bOID = Value.OIDValue + Else + If Value Is Nothing Then + Me._b = Nothing + Me._bOID = Nothing + Else + If Not Me._b.Equals(Value) Then + Me._b = Value + Me._bOID = Value.OIDValue + End If + End If + End If + Me.SetDirtyFlag() + End Set + End Property + + Public Property BOID() As String + Get + If Not (Me._b Is Nothing) Then + Return Me._b.OIDValue + Else + Return Me._bOID + End If + End Get + Set(ByVal Value As String) + If Not (Me._b Is Nothing) Then + If Not (Me._b.OIDValue = Value) Then + Me._b.OIDValue = Value + Me.SetDirtyFlag() + End If + End If + Me._bOID = Value + End Set + End Property + + Public Overloads Overrides Function getNewObject() As CPersistentObject + Return New N + End Function + + Public Overloads Overrides Function IsValid() As Boolean + Return True + End Function + End Class End Namespace \ No newline at end of file Index: SuperClassTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SuperClassTests.vb,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SuperClassTests.vb 21 Dec 2004 22:00:01 -0000 1.4 +++ SuperClassTests.vb 2 Jan 2005 09:41:10 -0000 1.5 @@ -175,5 +175,49 @@ Assert.AreEqual(124, j.Id) End Sub + <Test()> Public Sub MultiRetreiveCreteria() + Dim a As A + Dim b As B + Dim n As N + + a = New A + a.Id = 5 + a.Text = "Instance of class A" + + b = New B + b.Id = 1 + b.Text = "Instance of class B" + b.A = a + a.BCol.Add(b) + + n = New N + n.I = 7 + n.B = b + b.NCol.Add(n) + + a.Save() + + pbroker.ClearCache() + + Dim mrc As New CMultiRetrieveCriteria + Dim a1 As New A + Dim cpo As CPersistentObject + Dim c As CCursor + + cpo = CType(a1, A) + mrc.addObjectToJoin(a1, Nothing, "") + mrc.ClassMap = cpo.getClassMap + mrc.ReturnFullObjects = True + mrc.WhereCondition.ClassMap = cpo.getClassMap + mrc.WhereCondition.addSelectEqualTo("Id", 5) + c = mrc.perform + c.loadObject(cpo, pbroker) + cpo.Retrieve(cpo) + + a1 = CType(cpo, A) + + Assert.AreEqual(1, a1.BCol.Count, "Number of objects in collection is grater then 1") + + End Sub End Class End Namespace \ No newline at end of file |