From: Richard B. <rb...@us...> - 2004-10-25 07:14:24
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27457/InheritedClasses Modified Files: AtomsFrameworkTests.vb MultiRetrieveTestClasses.vb SharedTests.vb Added Files: ManyToManyClasses.vb ManyToManyTests.vb Log Message: Fix for cache problems when changing key values of objects that don't inherit from CPersistentObject Also fixed problem where many-to-many associations tried to save associationclass multiple times. --- NEW FILE: ManyToManyClasses.vb --- Imports AToMSFramework Namespace InheritedClasses #Region "ManyToManyA" Public Class ManyToManyA Inherits CPersistentObject Private _description As String Private _abCol As M2MABCollection Public Property Description() As String Get Return _description End Get Set(ByVal Value As String) _description = Value SetDirtyFlag() End Set End Property Public Property M2MABCollection() As M2MABCollection Get Return _abCol End Get Set(ByVal Value As M2MABCollection) _abCol = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New ManyToManyA End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() _abCol = New M2MABCollection _abCol.ContainerObject = Me End Sub Default Public Overrides ReadOnly Property Item(ByVal columnName As String) As String Get End Get End Property End Class #End Region #Region "ManyToManyB" Public Class ManyToManyB Inherits CPersistentObject Private _description As String Private _abCol As M2MABCollection Public Property Description() As String Get Return _description End Get Set(ByVal Value As String) _description = Value SetDirtyFlag() End Set End Property Public Property M2MABCollection() As M2MABCollection Get Return _abCol End Get Set(ByVal Value As M2MABCollection) _abCol = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New ManyToManyAB End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() _abCol = New M2MABCollection _abCol.ContainerObject = Me End Sub End Class #End Region #Region "ManyToManyAB" Public Class ManyToManyAB Inherits CPersistentObject Private _aGuid As Guid = Guid.Empty Private _bGuid As Guid = Guid.Empty Private _a As ManyToManyA Private _b As ManyToManyB Public Property AGuidValue() As String Get If _aGuid.Equals(Guid.Empty) Then _aGuid = Guid.NewGuid End If Return _aGuid.ToString("N") End Get Set(ByVal value As String) _aGuid = New Guid(value) SetDirtyFlag() End Set End Property Public Property BGuidValue() As String Get If _bGuid.Equals(Guid.Empty) Then _bGuid = Guid.NewGuid End If Return _bGuid.ToString("N") End Get Set(ByVal value As String) _bGuid = New Guid(value) SetDirtyFlag() End Set End Property Public Property M2MA() As ManyToManyA Get Return _a End Get Set(ByVal Value As ManyToManyA) _a = Value AGuidValue = _a.GUIDValue End Set End Property Public Property M2MB() As ManyToManyB Get Return _b End Get Set(ByVal Value As ManyToManyB) _b = Value BGuidValue = _b.GUIDValue End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New ManyToManyAB End Function Public Overrides Function IsValid() As Boolean Return True End Function End Class #End Region #Region "M2MABCollection" Public Class M2MABCollection Inherits CPersistentCollection Public Overloads Sub Add(ByVal ab As ManyToManyAB) MyBase.Add(ab) End Sub Public Overloads Sub Add(ByVal b As ManyToManyB) Dim ab As ManyToManyAB If Me.ContainerObject.GetType Is GetType(ManyToManyA) Then ab = New ManyToManyAB ab.M2MA = CType(Me.ContainerObject, ManyToManyA) ab.M2MB = b If Not list.Contains(ab) Then Add(ab) Else Throw New Exception("The b object is already in the collection") End If Else Throw New Exception("This collection belongs to a B object. Add an A instead") End If End Sub Public Overloads Sub Add(ByVal a As ManyToManyA) Dim ab As ManyToManyAB If Me.ContainerObject.GetType Is GetType(ManyToManyB) Then ab = New ManyToManyAB ab.M2MA = a ab.M2MB = CType(Me.ContainerObject, ManyToManyB) If Not list.Contains(ab) Then Add(ab) Else Throw New Exception("The A object is already in the collection") End If Else Throw New Exception("This collection belongs to an A object. Add a B instead") End If End Sub Public Shadows Function Item(ByVal index As Integer) As ManyToManyAB Return CType(MyBase.Item(index), ManyToManyAB) End Function End Class #End Region End Namespace Index: SharedTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/SharedTests.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SharedTests.vb 19 Oct 2004 03:30:42 -0000 1.2 +++ SharedTests.vb 25 Oct 2004 07:14:15 -0000 1.3 @@ -48,7 +48,7 @@ sc = New SharedChild newOid = sc.OIDValue sc.OIDValue = origOid - result = sc.Retrieve(sc) + result = sc.Retrieve() Assert.IsTrue(sc.OIDValue = origOid) Assert.IsTrue(origOid <> newOid) Assert.IsTrue(result) @@ -64,7 +64,7 @@ sc.Save() origOid = sc.OIDValue sp.OIDValue = origOid - result = sp.Retrieve(sp) + result = sp.Retrieve() Assert.IsTrue(sp.OIDValue = origOid) Assert.IsTrue(result) Assert.IsFalse(sp.IsDirty) --- NEW FILE: ManyToManyTests.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class ManyToManyTests Private pbroker As CPersistenceBroker Private A As ManyToManyA Private B As ManyToManyB Private mrc As CMultiRetrieveCriteria Private rc As CRetrieveCriteria Private c As CCursor <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" Dim retry As Boolean = True While retry = True Try 'Remove any existing test database System.IO.File.Delete(".\db1.mdb") retry = False Catch iox As IO.IOException 'file is in use - so we will loop around until it is released GC.Collect() Catch ex As Exception retry = False End Try End While System.IO.File.Copy(".\original db1.mdb", ".\db1.mdb") pbroker = New CPersistenceBroker pbroker.init() End Sub <TestFixtureTearDown()> Public Sub Dispose() pbroker.Dispose() pbroker = Nothing End Sub <Test()> Public Sub SaveThenRetrieve() Dim gval As String Dim x As Integer, y As Integer A = New ManyToManyA A.Description = "A-one" gval = A.GUIDValue B = New ManyToManyB B.Description = "B-one" A.M2MABCollection.Add(B) B.M2MABCollection.Add(A) Dim B2 As ManyToManyB = New ManyToManyB B2.Description = "B-two" A.M2MABCollection.Add(B2) Dim A2 As ManyToManyA = New ManyToManyA A2.Description = "A-two" B2.M2MABCollection.Add(A2) A.Save() pbroker.ClearCache() A = New ManyToManyA A.GUIDValue = gval A.Retrieve() Assert.AreEqual(2, A.M2MABCollection.Count) 'Order of guids can affect order of the collection If A.M2MABCollection.Item(0).M2MB.M2MABCollection.Count = 1 Then x = 0 y = 1 Else x = 1 y = 0 End If B = A.M2MABCollection.Item(x).M2MB Assert.IsNotNull(B) Assert.AreEqual("B-one", B.Description) Assert.AreEqual(1, B.M2MABCollection.Count) Assert.IsTrue(A.Equals(B.M2MABCollection.Item(0).M2MA)) B = A.M2MABCollection.Item(y).M2MB Assert.IsNotNull(B) Assert.AreEqual("B-two", B.Description) Assert.AreEqual(2, B.M2MABCollection.Count) End Sub End Class End Namespace Index: MultiRetrieveTestClasses.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/MultiRetrieveTestClasses.vb,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- MultiRetrieveTestClasses.vb 19 Oct 2004 03:30:42 -0000 1.1 +++ MultiRetrieveTestClasses.vb 25 Oct 2004 07:14:14 -0000 1.2 @@ -101,7 +101,7 @@ Return _field2 End Get Set(ByVal Value As Integer) - _field1 = Value + _field2 = Value End Set End Property @@ -171,7 +171,7 @@ Return _field2 End Get Set(ByVal Value As Integer) - _field1 = Value + _field2 = Value End Set End Property Index: AtomsFrameworkTests.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/AtomsFrameworkTests.vb,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- AtomsFrameworkTests.vb 21 Oct 2004 23:36:46 -0000 1.3 +++ AtomsFrameworkTests.vb 25 Oct 2004 07:14:14 -0000 1.4 @@ -130,7 +130,7 @@ emp.Find() Assert.IsTrue(emp.Persistent) Assert.AreEqual(emp.Workers.Count, 3) - emp = emp.Workers.Item(1) + emp = CType(emp.Workers.Item(1), CEmployee) Assert.AreEqual(emp.Name, "aa") Assert.AreEqual(emp.ReportsTo.Name, "ac") End Sub |