From: Dan M. <dan...@us...> - 2004-12-21 08:52:56
|
Update of /cvsroot/jcframework/Nunit/InheritedClasses In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4418/Nunit/InheritedClasses Modified Files: SuperClassTests.vb tblAtoKClasses.vb Log Message: Add a test case to check that for an inherited child class that has an association defined in the XML mapping file, and does not have an instance of the association in the database, the framework does not create the object in the association. Index: tblAtoKClasses.vb =================================================================== RCS file: /cvsroot/jcframework/Nunit/InheritedClasses/tblAtoKClasses.vb,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- tblAtoKClasses.vb 21 Dec 2004 00:10:31 -0000 1.2 +++ tblAtoKClasses.vb 21 Dec 2004 08:52:46 -0000 1.3 @@ -43,25 +43,29 @@ Public Property C() As C Get - 'Retrieving manually when we have an association set to autoretrieve can produce - 'unpredictable results. - 'If _c Is Nothing AndAlso _cOID <> String.Empty Then - ' _c = New C - ' _c.OIDValue = _cOID - ' _c.Retrieve() + 'If _c Is Nothing Then + '_c = New C + '_c.OIDValue = _cOID + '_c.Retrieve() 'End If Return _c End Get Set(ByVal Value As C) - If Not CPersistentObject.Equals(_c, Value) Then - _c = Value + If Me._c Is Nothing AndAlso Not (Value Is Nothing) Then + Me._c = Value + Me._cOID = Value.OIDValue + Else If Value Is Nothing Then - _cOID = "" + Me._c = Nothing + Me._cOID = Nothing Else - _cOID = Value.OIDValue + If Not Me._c.Equals(Value) Then + Me._c = Value + Me._cOID = Value.OIDValue + End If End If - SetDirtyFlag() End If + Me.SetDirtyFlag() End Set End Property @@ -263,6 +267,8 @@ Public Sub New() End Sub Private _str As String = String.Empty + Private _m As M = Nothing + Private _mOID As String Public Property Str() As String Get @@ -276,6 +282,48 @@ End Set End Property + Public Property M1() + Get + Return Me._m + End Get + Set(ByVal Value) + If Me._m Is Nothing AndAlso Not (Value Is Nothing) Then + Me._m = Value + Me._mOID = Value.OIDValue + Else + If Value Is Nothing Then + Me._m = Nothing + Me._mOID = Nothing + Else + If Not Me._m.Equals(Value) Then + Me._m = Value + Me._mOID = Value.OIDValue + End If + End If + End If + Me.SetDirtyFlag() + End Set + End Property + + Public Property M1OID() + Get + If Not Me._m Is Nothing Then + Return Me._m.OIDValue + Else + Return Me._mOID + End If + End Get + Set(ByVal Value) + If Not Me._m Is Nothing Then + If Not Me._m.OIDValue.Equals(Value) Then + Me._m.OIDValue = Value + Me.SetDirtyFlag() + End If + End If + Me._mOID = Value + End Set + End Property + Public Overloads Overrides Function getNewObject() As CPersistentObject Return New E End Function @@ -319,6 +367,8 @@ Public Sub New() End Sub Private _i As Integer = 0 + Private _m As M = Nothing + Private _mOID As String = Nothing Public Property I() As Integer Get @@ -332,6 +382,48 @@ End Set End Property + Public Property M() + Get + Return Me._m + End Get + Set(ByVal Value) + If Me._m Is Nothing AndAlso Not (Value Is Nothing) Then + Me._m = Value + Me._mOID = Value.OIDValue + Else + If Value Is Nothing Then + Me._m = Nothing + Me._mOID = Nothing + Else + If Not Me._m.Equals(Value) Then + Me._m = Value + Me._mOID = Value.OIDValue + End If + End If + End If + Me.SetDirtyFlag() + End Set + End Property + + Public Property MOID() + Get + If Not Me._m Is Nothing Then + Return Me._m.OIDValue + Else + Return Me._mOID + End If + End Get + Set(ByVal Value) + If Not Me._m Is Nothing Then + If Not Me._m.OIDValue.Equals(Value) Then + Me._m.OIDValue = Value + Me.SetDirtyFlag() + End If + End If + Me._mOID = Value + End Set + End Property + Public Overloads Overrides Function getNewObject() As CPersistentObject Return New G End Function @@ -347,6 +439,8 @@ Public Sub New() End Sub Private _str As String = String.Empty + Private _m As M = Nothing + Private _mOID As String Public Property Str() As String Get @@ -360,6 +454,48 @@ End Set End Property + Public Property M1() + Get + Return Me._m + End Get + Set(ByVal Value) + If Me._m Is Nothing AndAlso Not (Value Is Nothing) Then + Me._m = Value + Me._mOID = Value.OIDValue + Else + If Value Is Nothing Then + Me._m = Nothing + Me._mOID = Nothing + Else + If Not Me._m.Equals(Value) Then + Me._m = Value + Me._mOID = Value.OIDValue + End If + End If + End If + Me.SetDirtyFlag() + End Set + End Property + + Public Property M1OID() + Get + If Not Me._m Is Nothing Then + Return Me._m.OIDValue + Else + Return Me._mOID + End If + End Get + Set(ByVal Value) + If Not Me._m Is Nothing Then + If Not Me._m.OIDValue.Equals(Value) Then + Me._m.OIDValue = Value + Me.SetDirtyFlag() + End If + End If + Me._mOID = Value + End Set + End Property + Public Overloads Overrides Function getNewObject() As CPersistentObject Return New H End Function @@ -431,6 +567,8 @@ Public Sub New() End Sub Private _i As Integer = 0 + Private _m As M = Nothing + Private _mOID As String Public Property I() As Integer Get @@ -444,6 +582,48 @@ End Set End Property + Public Property M() + Get + Return Me._m + End Get + Set(ByVal Value) + If Me._m Is Nothing AndAlso Not (Value Is Nothing) Then + Me._m = Value + Me._mOID = Value.OIDValue + Else + If Value Is Nothing Then + Me._m = Nothing + Me._mOID = Nothing + Else + If Not Me._m.Equals(Value) Then + Me._m = Value + Me._mOID = Value.OIDValue + End If + End If + End If + Me.SetDirtyFlag() + End Set + End Property + + Public Property MOID() + Get + If Not Me._m Is Nothing Then + Return Me._m.OIDValue + Else + Return Me._mOID + End If + End Get + Set(ByVal Value) + If Not Me._m Is Nothing Then + If Not Me._m.OIDValue.Equals(Value) Then + Me._m.OIDValue = Value + Me.SetDirtyFlag() + End If + End If + Me._mOID = Value + End Set + End Property + Public Overloads Overrides Function getNewObject() As CPersistentObject Return New K End Function @@ -452,4 +632,33 @@ Return True End Function End Class + + Public Class M + Inherits CPersistentObject + + Public Sub New() + End Sub + Private _i As Integer = 0 + + 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 Overloads Overrides Function getNewObject() As CPersistentObject + Return New M + 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.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SuperClassTests.vb 21 Dec 2004 00:10:31 -0000 1.2 +++ SuperClassTests.vb 21 Dec 2004 08:52:46 -0000 1.3 @@ -8,7 +8,7 @@ Private pbroker As CPersistenceBroker <TestFixtureSetUp()> Public Sub Init() - Environment.CurrentDirectory = "C:\Projects\MMM\Nunit_AtomsFramework" + Environment.CurrentDirectory = "C:\My Programs\JCFramework\Nunit" Dim retry As Boolean = True While retry = True Try @@ -35,6 +35,18 @@ <SetUp()> Public Sub TestInit() End Sub + <TearDown()> Public Sub TestEnd() + pbroker.ClearCache() + Dim col As CPersistentCollection + Dim cpo As CPersistentObject = New A + col = cpo.getAll(True) + + For Each a As A In col + a.Delete(True) + Next + pbroker.ClearCache() + End Sub + <Test()> Public Sub CheckMultiInheritance1() Dim root As New A root.Id = 1 @@ -76,6 +88,47 @@ Next End Sub + <Test()> Public Sub CheckMultiInheritance2() + Dim root As New A + root.Id = 1 + root.Text = "Root object" + root.BCol = New CPersistentCollection + ' create G and add it to the collection + Dim g As New G + g.Id = 5 + g.Text = "Child class of E" + g.Str = "Added to collection" + g.I = 555 + g.A = root + root.BCol.Add(g) + + ' create oneToOne object (K) and add it to root + Dim k As New K + k.Id = 6 + k.Text = "Child of class H" + k.Str = "Added to oneToOne association" + k.I = 666 + root.C = k + + 'save root (class A) + root.Save(True) + 'Now check that A, G and K are in the database + 'Console.WriteLine("\nIf you'll check the data in the tables,\nyou'll find that tblA is populated and tables tblG and tbl K are populated.\nBut tables tblE, tblC, tblH are not populated at all.\n"); + pbroker.ClearCache() + Dim col As CPersistentCollection + Dim cpo As CPersistentObject = New A + col = cpo.getAll(True) + + Assert.IsTrue(col.Count > 0) + For Each a As A In col + Assert.IsNull(CType(CType(a.C, K).M, M), "Object is not NULL") + For Each b As B In a.BCol + Assert.IsTrue(b.GetType Is GetType(G)) + Assert.IsNull(CType(CType(b, G).M1, M), "Object is not NULL") + Next + Next + End Sub + <Test()> Public Sub RetrievalViaParentAttributes() Dim j As New J j.I = 1 @@ -98,7 +151,7 @@ cursor.loadObject(j) Assert.AreEqual("Class C Text", j.Text) Assert.AreEqual("Class H Str", j.Str) - assert.AreEqual(123,j.Id) + Assert.AreEqual(123, j.Id) End Sub <Test()> Public Sub RetrievalViaParentAttributes2() |