From: Richard B. <rb...@us...> - 2005-02-09 06:21:04
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28234/InheritedClasses Added Files: ManyToManyClasses_v2.vb ManyToManyTests_v2.vb Log Message: Unit test for new Many-to-Many associations --- NEW FILE: ManyToManyClasses_v2.vb --- Imports AToMSFramework Namespace InheritedClasses #Region "M2MA" Public Class M2MA Inherits CPersistentObject Private _description As String Private _bCol As M2MBCollection Public Property Description() As String Get Return _description End Get Set(ByVal Value As String) _description = Value SetDirtyFlag() End Set End Property Public Property M2MBCollection() As M2MBCollection Get Return _bCol End Get Set(ByVal Value As M2MBCollection) _bCol = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New M2MA End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() _bCol = New M2MBCollection _bCol.ContainerObject = Me End Sub End Class #End Region #Region "M2MB" Public Class M2MB Inherits CPersistentObject Private _description As String Private _aCol As M2MACollection Public Property Description() As String Get Return _description End Get Set(ByVal Value As String) _description = Value SetDirtyFlag() End Set End Property Public Property M2MACollection() As M2MACollection Get Return _aCol End Get Set(ByVal Value As M2MACollection) _aCol = Value End Set End Property Public Overrides Function getNewObject() As AToMSFramework.CPersistentObject Return New M2MB End Function Public Overrides Function IsValid() As Boolean Return True End Function Public Sub New() _aCol = New M2MACollection _aCol.ContainerObject = Me End Sub End Class #End Region #Region "M2MACollection" Public Class M2MACollection Inherits CPersistentCollection Public Overloads Sub Add(ByVal a As M2MA) list.Add(a) End Sub Public Shadows Function Item(ByVal index As Integer) As M2MA Return CType(MyBase.Item(index), M2MA) End Function End Class #End Region #Region "M2MBCollection" Public Class M2MBCollection Inherits CPersistentCollection Public Overloads Sub Add(ByVal b As M2MB) list.Add(b) End Sub Public Shadows Function Item(ByVal index As Integer) As M2MB Return CType(MyBase.Item(index), M2MB) End Function End Class #End Region End Namespace --- NEW FILE: ManyToManyTests_v2.vb --- Imports AToMSFramework Imports NUnit.Framework Namespace InheritedClasses <TestFixture()> Public Class ManyToManyTests_v2 Private pbroker As CPersistenceBroker Private A As M2MA Private B As M2MB <TestFixtureSetUp()> Public Sub Init() Environment.CurrentDirectory = System.AppDomain.CurrentDomain.BaseDirectory 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 M2MA A.Description = "A-one" gval = A.GUIDValue B = New M2MB B.Description = "B-one" A.M2MBCollection.Add(B) B.M2MACollection.Add(A) Dim B2 As M2MB = New M2MB B2.Description = "B-two" A.M2MBCollection.Add(B2) Dim A2 As M2MA = New M2MA A2.Description = "A-two" B2.M2MACollection.Add(A2) A.Save() pbroker.ClearCache() A = New M2MA A.GUIDValue = gval A.Retrieve() Assert.AreEqual(2, A.M2MBCollection.Count) 'Order of guids can affect order of the collection If A.M2MBCollection.Item(0).M2MACollection.Count = 1 Then x = 0 y = 1 Else x = 1 y = 0 End If B = A.M2MBCollection.Item(x) Assert.IsNotNull(B) Assert.AreEqual("B-one", B.Description) Assert.AreEqual(1, B.M2MACollection.Count) Assert.IsTrue(A.Equals(B.M2MACollection.Item(0))) B = A.M2MBCollection.Item(y) Assert.IsNotNull(B) Assert.AreEqual("B-two", B.Description) Assert.AreEqual(2, B.M2MACollection.Count) End Sub End Class End Namespace |