...
Ideally I should be able to drop in any kind of persister I want without making code changes. And in fact I have written one such persister for TPS files. I'll explain how it works next time; for now, here's theĀ unit test code to make sure that saving and loading works as expected.
Code Block |
---|
DeleteSaveAndLoadDataSaveAndLoadData 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('DeleteSaveAndLoadDataSaveAndLoadData') Filename = longpath() & '\CML_Data_ManyToManyLinksTests.tps' if exists(filename) remove(filename) end AssertThat(exists(filename),IsEqualTo(false),'Could not delete ' & filename) 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') |
...