@@ -281,6 +281,110 @@ class OfflineReadTests: _AzureDataTests {
281281 wait ( for: [ deleteExpectation] , timeout: timeout)
282282 }
283283
284+ func testEmptyChildDirectoriesAreCreatedWhenANewDatabaseIsCachedOffline( ) {
285+ let createExpectation = self . expectation ( description: " empty child directories are created when a new database is cached offline. " )
286+
287+ ensureDatabaseExists { database in
288+ AzureData . get ( databaseWithId: database. id) { r in
289+ XCTAssertTrue ( r. result. isSuccess)
290+
291+ self . wait {
292+ let databaseDirectoryUrl = URL ( string: " dbs/ \( database. resourceId) / " , relativeTo: self . cachesDirectoryURL) !
293+ let collectionsDirectoryUrl = URL ( string: " colls/ " , relativeTo: databaseDirectoryUrl) !
294+ let usersDirectoryUrl = URL ( string: " users/ " , relativeTo: databaseDirectoryUrl) !
295+
296+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: databaseDirectoryUrl. path) )
297+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: collectionsDirectoryUrl. path) )
298+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: usersDirectoryUrl. path) )
299+
300+ createExpectation. fulfill ( )
301+ }
302+ }
303+ }
304+
305+ wait ( for: [ createExpectation] , timeout: timeout)
306+ }
307+
308+ func testEmptyChildDirectoriesAreCreatedWhenANewCollectionIsCachedOffline( ) {
309+ let createExpectation = self . expectation ( description: " empty child directories are created when a new collection is cached offline. " )
310+
311+ ensureDatabaseExists { database in
312+ self . ensureCollectionExists { collection in
313+ AzureData . get ( collectionWithId: collection. id, inDatabase: database. id) { r in
314+ XCTAssertTrue ( r. result. isSuccess)
315+
316+ self . wait {
317+ let collectionDirectoryUrl = URL ( string: " dbs/ \( database. resourceId) /colls/ \( collection. resourceId) / " , relativeTo: self . cachesDirectoryURL) !
318+ let documentsDirectoryUrl = URL ( string: " docs/ " , relativeTo: collectionDirectoryUrl) !
319+ let sprocsDirectoryUrl = URL ( string: " sprocs/ " , relativeTo: collectionDirectoryUrl) !
320+ let triggersDirectoryUrl = URL ( string: " triggers/ " , relativeTo: collectionDirectoryUrl) !
321+ let udfsDirectoryUrl = URL ( string: " udfs/ " , relativeTo: collectionDirectoryUrl) !
322+
323+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: collectionDirectoryUrl. path) )
324+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: documentsDirectoryUrl. path) )
325+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: sprocsDirectoryUrl. path) )
326+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: triggersDirectoryUrl. path) )
327+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: udfsDirectoryUrl. path) )
328+
329+ createExpectation. fulfill ( )
330+ }
331+ }
332+ }
333+ }
334+
335+ wait ( for: [ createExpectation] , timeout: timeout)
336+ }
337+
338+ func testEmptyChildDirectoriesAreCreatedWhenANewDocumentIsCachedOffline( ) {
339+ let createExpectation = self . expectation ( description: " empty child directories are created when a new document is cached offline. " )
340+
341+ ensureDatabaseExists { database in
342+ self . ensureCollectionExists { collection in
343+ self . ensureDocumentExists { document in
344+ AzureData . get ( documentWithId: document. id, as: Document . self, inCollection: collection. id, inDatabase: database. id) { r in
345+ XCTAssertTrue ( r. result. isSuccess)
346+
347+ self . wait {
348+ let documentDirectoryUrl = URL ( string: " dbs/ \( database. resourceId) /colls/ \( collection. resourceId) /docs/ \( document. resourceId) / " , relativeTo: self . cachesDirectoryURL) !
349+ let attachments = URL ( string: " attachments/ " , relativeTo: documentDirectoryUrl) !
350+
351+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: documentDirectoryUrl. path) )
352+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: attachments. path) )
353+
354+ createExpectation. fulfill ( )
355+ }
356+ }
357+ }
358+ }
359+ }
360+
361+ wait ( for: [ createExpectation] , timeout: timeout)
362+ }
363+
364+ func testEmptyChildDirectoriesAreCreatedWhenANewUserIsCachedOffline( ) {
365+ let createExpectation = self . expectation ( description: " empty child directories are created when a new user is cached offline. " )
366+
367+ ensureDatabaseExists { database in
368+ self . ensureUserExists { user in
369+ AzureData . get ( userWithId: user. id, inDatabase: database. id) { r in
370+ XCTAssertTrue ( r. result. isSuccess)
371+
372+ self . wait {
373+ let userDirectoryUrl = URL ( string: " dbs/ \( database. resourceId) /users/ \( user. resourceId) / " , relativeTo: self . cachesDirectoryURL) !
374+ let permissionsDirectoryUrl = URL ( string: " permissions/ " , relativeTo: userDirectoryUrl) !
375+
376+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: userDirectoryUrl. path) )
377+ XCTAssertTrue ( FileManager . default. fileExists ( atPath: permissionsDirectoryUrl. path) )
378+
379+ createExpectation. fulfill ( )
380+ }
381+ }
382+ }
383+ }
384+
385+ wait ( for: [ createExpectation] , timeout: timeout)
386+ }
387+
284388 // MARK: - Private helpers
285389
286390 private func ensureResourcesAreCachedLocallyWhenNetworkIsReachable< T: CodableResource > (
0 commit comments