@@ -16,6 +16,7 @@ public class CrdtRepairTests(SyncFixture fixture) : IClassFixture<SyncFixture>,
1616 private CrdtMiniLcmApi CrdtApi => _fixture . CrdtApi ;
1717 private FwDataMiniLcmApi FwDataApi => _fixture . FwDataApi ;
1818 private CrdtFwdataProjectSyncService SyncService => _fixture . SyncService ;
19+ private ProjectSnapshotService SnapshotService => _fixture . Services . GetRequiredService < ProjectSnapshotService > ( ) ;
1920 private static Entry TestEntry ( )
2021 {
2122 return new ( )
@@ -44,7 +45,7 @@ private static Entry TestEntry()
4445
4546 public async Task InitializeAsync ( )
4647 {
47- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
48+ await SyncService . Import ( CrdtApi , FwDataApi ) ;
4849 }
4950
5051 public async Task DisposeAsync ( )
@@ -89,8 +90,9 @@ public async Task CrdtEntryMissingTranslationId_NoChanges_FullSync()
8990 var fwTranslationId = fwEntry . SingleTranslation ( ) . Id ;
9091
9192 // act
92- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
93- await SyncService . RegenerateProjectSnapshot ( CrdtApi , FwDataApi . Project ) ;
93+ var projectSnapshot = await GetSnapshot ( ) ;
94+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
95+ await SnapshotService . RegenerateProjectSnapshot ( CrdtApi , FwDataApi . Project ) ;
9496
9597 // assert - the fwdata ID is now used everywhere
9698 var updatedFwEntry = await FwDataApi . GetEntry ( crdtEntry . Id ) ;
@@ -116,7 +118,8 @@ public async Task CrdtEntryMissingTranslationId_FwTranslationChanged_FullSync()
116118 var translationUpdate = new UpdateObjectInput < Translation > ( ) . Set ( t => t . Text [ "en" ] , new RichString ( "changed translation" , "en" ) ) ;
117119 await FwDataApi . UpdateTranslation ( fwEntry . Id , fwEntry . Senses . Single ( ) . Id , fwEntry . SingleExampleSentence ( ) . Id ,
118120 fwTranslationId , translationUpdate ) ;
119- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
121+ var projectSnapshot = await GetSnapshot ( ) ;
122+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
120123
121124 // assert
122125 var crdtEntryAfter = await CrdtApi . GetEntry ( crdtEntry . Id ) ;
@@ -135,7 +138,8 @@ public async Task CrdtEntryMissingTranslationId_CrdtTranslationChanged_FullSync(
135138 var translationUpdate = new UpdateObjectInput < Translation > ( ) . Set ( t => t . Text [ "en" ] , new RichString ( "changed translation" , "en" ) ) ;
136139 await CrdtApi . UpdateTranslation ( crdtEntry . Id , crdtEntry . Senses . Single ( ) . Id , crdtEntry . SingleExampleSentence ( ) . Id ,
137140 crdtEntry . SingleTranslation ( ) . Id , translationUpdate ) ;
138- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
141+ var projectSnapshot = await GetSnapshot ( ) ;
142+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
139143
140144 // assert
141145 var fwEntryAfter = await FwDataApi . GetEntry ( fwEntry . Id ) ;
@@ -156,8 +160,9 @@ public async Task CrdtEntryMissingTranslationId_MultipleFwTranslations_FullSync(
156160 fwEntry = await FwDataApi . GetEntry ( fwEntry . Id ) ;
157161
158162 // act
159- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
160- await SyncService . RegenerateProjectSnapshot ( CrdtApi , FwDataApi . Project ) ;
163+ var projectSnapshot = await GetSnapshot ( ) ;
164+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
165+ await SnapshotService . RegenerateProjectSnapshot ( CrdtApi , FwDataApi . Project ) ;
161166
162167 // assert - the fwdata ID is now used everywhere
163168 var updatedFwEntry = await FwDataApi . GetEntry ( crdtEntry . Id ) ;
@@ -208,7 +213,8 @@ public async Task CrdtEntryMissingTranslationId_FwTranslationRemoved_FullSync()
208213
209214 // act
210215 await FwDataApi . RemoveTranslation ( entryId , senseId , exampleSentenceId , fwTranslationId ) ;
211- var result = await SyncService . Sync ( CrdtApi , FwDataApi ) ;
216+ var projectSnapshot = await GetSnapshot ( ) ;
217+ var result = await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
212218 result . CrdtChanges . Should ( ) . Be ( 1 , "the crdt translation was removed" ) ;
213219
214220 // assert - the crdt translation was also removed
@@ -227,7 +233,8 @@ public async Task CrdtEntryMissingTranslationId_FwExampleSentenceRemoved_FullSyn
227233
228234 // act
229235 await FwDataApi . DeleteExampleSentence ( entryId , senseId , exampleSentenceId ) ;
230- var result = await SyncService . Sync ( CrdtApi , FwDataApi ) ;
236+ var projectSnapshot = await GetSnapshot ( ) ;
237+ var result = await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
231238 result . CrdtChanges . Should ( ) . Be ( 1 , "the crdt example-sentence was removed" ) ;
232239
233240 // assert - the crdt translation was also removed
@@ -269,7 +276,8 @@ public async Task CrdtEntryMissingTranslationId_CrdtTranslationRemoved_FullSync(
269276
270277 // act
271278 await CrdtApi . RemoveTranslation ( entryId , senseId , exampleSentenceId , fwExample . DefaultFirstTranslationId ) ;
272- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
279+ var projectSnapshot = await GetSnapshot ( ) ;
280+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
273281
274282 // assert - the fw translation was also removed
275283 var updatedFwEntry = await FwDataApi . GetEntry ( crdtEntry . Id ) ;
@@ -287,7 +295,8 @@ public async Task CrdtEntryMissingTranslationId_CrdtExampleSentenceRemoved_FullS
287295
288296 // act
289297 await CrdtApi . DeleteExampleSentence ( entryId , senseId , exampleSentenceId ) ;
290- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
298+ var projectSnapshot = await GetSnapshot ( ) ;
299+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
291300
292301 // assert - the fw translation was also removed
293302 var updatedFwEntry = await FwDataApi . GetEntry ( crdtEntry . Id ) ;
@@ -321,7 +330,8 @@ public async Task CrdtEntryMissingTranslationId_NewCrdtEntry_FullSync()
321330 var crdtEntry = await CrdtApi . CreateEntry ( entry ) ;
322331
323332 // act
324- await SyncService . Sync ( CrdtApi , FwDataApi ) ;
333+ var projectSnapshot = await GetSnapshot ( ) ;
334+ await SyncService . Sync ( CrdtApi , FwDataApi , projectSnapshot ) ;
325335
326336 // assert - the default ID was used in the new fw translation
327337 var fwEntry = await FwDataApi . GetEntry ( crdtEntry . Id ) ;
@@ -341,7 +351,7 @@ public async Task CrdtEntryMissingTranslationId_NewCrdtEntry_FullSync()
341351 var snapshot = await CrdtApi . TakeProjectSnapshot ( ) ;
342352 var snapshotEntry = snapshot . Entries . Single ( e => e . Id == crdtEntry . Id ) ;
343353 snapshotEntry . SingleTranslation ( ) . Id = Translation . MissingTranslationId ;
344- await CrdtFwdataProjectSyncService . SaveProjectSnapshot ( FwDataApi . Project , snapshot ) ;
354+ await ProjectSnapshotService . SaveProjectSnapshot ( FwDataApi . Project , snapshot ) ;
345355
346356 // assert
347357 // snapshot reflects the missing ID
@@ -367,10 +377,16 @@ public async Task CrdtEntryMissingTranslationId_NewCrdtEntry_FullSync()
367377
368378 private async Task < Entry [ ] > GetSnapshotEntries ( )
369379 {
370- var snapshot = await SyncService . GetProjectSnapshot ( FwDataApi . Project ) ;
380+ var snapshot = await SnapshotService . GetProjectSnapshot ( FwDataApi . Project ) ;
371381 return snapshot ? . Entries ?? [ ] ;
372382 }
373383
384+ private async Task < ProjectSnapshot > GetSnapshot ( )
385+ {
386+ return await SnapshotService . GetProjectSnapshot ( FwDataApi . Project )
387+ ?? throw new InvalidOperationException ( "Expected snapshot to exist" ) ;
388+ }
389+
374390}
375391#pragma warning restore CS0618 // Type or member is obsolete
376392
0 commit comments