In the previous installment I wrote a successful unit test that saved and loaded checkbox data. By way of refresher, here's that code:
Code Block |
---|
DeleteSaveAndLoadData PROCEDURE (*long addr) ! Declare Procedure
ManytoMany CML_Data_ManyToManyLinks
itemize(),pre()
RightRecordX equate
RightRecordY equate
RightRecordZ equate
end
Persister CML_Data_ManyToManyLinksPersisterForTPS
Filename cstring(500)
CODE
addr = address(UnitTestResult)
BeginUnitTest('DeleteSaveAndLoadData')
Persister.SetFilename(Filename)
ManytoMany.Persister &= Persister
ManyToMany.LeftRecordID = 1
ManyToMany.SetLinkTo(RightRecordX)
ManyToMany.SetLinkTo(RightRecordZ)
AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(true), 'before save, record X should be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'before save, record Y should not be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(true), 'before save, record Z should be linked')
ManyToMany.Save()
ManyToMany.Reset()
AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(false),'after reset, record X should not be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'after reset, record Y should not be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(false),'after reset, record Z should not be linked')
ManytoMany.Load()
AssertThat(ManyToMany.IsLinkedTo(RightRecordX),IsEqualTo(true), 'after load, record X should be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordY),IsEqualTo(false),'after load, record Y should not be linked')
AssertThat(ManyToMany.IsLinkedTo(RightRecordZ),IsEqualTo(true), 'after load, record Z should be linked') |
You can ignore the first two lines of code as they're standard setup for the unit test procedure, and required by ClarionTest.
First I assign the Persister object to the ManyToMany object.
Then set some links and very that the ManyToMany object correctly maintains those links.
I call ManyToMany.Save(), which as you'll recall from last time checks to see if there's a Persister object, and if there is one it calls that object's Save method.
I then call ManyToMany.Reset() and verify that all the previous associations have been wiped out, so I can be sure that anything I test after a Load() is there because of Load().
And finally I Load() the saved values and verify that ManyToMany now has the expected state.
Here's the code for