public void TestCreateRootDirectoryIfNecessary() { DynamicDefaultDiskStorage supplier = CreateInternalCacheDirStorage(); Assert.IsNull(supplier._currentState.DiskStorageDelegate); DirectoryInfo cacheDir = new DirectoryInfo(ApplicationData.Current.LocalCacheFolder.Path); DirectoryInfo baseDir = new DirectoryInfo(Path.Combine(cacheDir.FullName, _baseDirectoryName)); // Directory is clean supplier.CreateRootDirectoryIfNecessary(baseDir); baseDir.Refresh(); Assert.IsTrue(baseDir.Exists); // Cleanup FileTree.DeleteRecursively(baseDir); // A file with the same name exists - this should clobber the file, and create a directory // instead FileInfo dummyFile = new FileInfo(Path.Combine(cacheDir.FullName, _baseDirectoryName)); Assert.IsTrue(dummyFile.CreateEmpty()); Assert.IsTrue(dummyFile.Exists); supplier.CreateRootDirectoryIfNecessary(baseDir); baseDir.Refresh(); Assert.IsTrue(baseDir.Exists); // Cleanup FileTree.DeleteRecursively(baseDir); // A directory with the same name exists - and with a file in it. // Everything should stay the same baseDir.Create(); FileInfo dummyFile2 = new FileInfo(Path.Combine(baseDir.FullName, "dummy1")); Assert.IsTrue(dummyFile2.CreateEmpty()); Assert.IsTrue(dummyFile2.Exists); supplier.CreateRootDirectoryIfNecessary(baseDir); baseDir.Refresh(); dummyFile2.Refresh(); Assert.IsTrue(dummyFile2.Exists); }