public void FileExists_Existance(PresetScopes scope) { using (var isf = GetPresetScope(scope)) { string root = isf.GetUserRootDirectory(); string file = "FileExists_Existance"; isf.CreateTestFile(file); Assert.True(File.Exists(Path.Combine(root, file)), "exists per file.io where expected"); Assert.True(isf.FileExists(file), "exists per iso"); isf.DeleteFile(file); Assert.False(File.Exists(Path.Combine(root, file)), "doesn't exist per file.io where expected"); Assert.False(isf.FileExists(file), "doesn't exist per iso"); // Now nested isf.CreateDirectory(file); file = Path.Combine(file, file); isf.CreateTestFile(file); Assert.True(File.Exists(Path.Combine(root, file)), "exists nested per file.io where expected"); Assert.True(isf.FileExists(file), "exists nested per iso"); isf.DeleteFile(file); Assert.False(File.Exists(Path.Combine(root, file)), "doesn't exist nested per file.io where expected"); Assert.False(isf.FileExists(file), "doesn't exist nested per iso"); } }
public void DeleteDirectory_DeletesDirectory(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string directory = "DeleteDirectory_DeletesDirectory"; string subdirectory = Path.Combine(directory, directory); isf.CreateDirectory(directory); Assert.True(isf.DirectoryExists(directory), "directory exists"); isf.CreateDirectory(subdirectory); Assert.True(isf.DirectoryExists(subdirectory), "subdirectory exists"); // Can't delete a directory with content Assert.Throws<IsolatedStorageException>(() => isf.DeleteDirectory(directory)); Assert.True(isf.DirectoryExists(directory)); isf.DeleteDirectory(subdirectory); Assert.False(isf.DirectoryExists(subdirectory)); isf.DeleteDirectory(directory); Assert.False(isf.DirectoryExists(directory)); } }
public static IsolatedStorageFile GetPresetScope(PresetScopes scope) { switch (scope) { case PresetScopes.UserStoreForApplication: return(IsolatedStorageFile.GetUserStoreForApplication()); case PresetScopes.UserStoreForAssembly: return(IsolatedStorageFile.GetUserStoreForAssembly()); case PresetScopes.UserStoreForDomain: return(IsolatedStorageFile.GetUserStoreForDomain()); case PresetScopes.MachineStoreForApplication: return(IsolatedStorageFile.GetMachineStoreForApplication()); case PresetScopes.MachineStoreForAssembly: return(IsolatedStorageFile.GetMachineStoreForAssembly()); case PresetScopes.MachineStoreForDomain: return(IsolatedStorageFile.GetMachineStoreForDomain()); default: throw new InvalidOperationException("Unknown preset scope"); } }
public void DeleteDirectory_DeletesDirectory(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string directory = "DeleteDirectory_DeletesDirectory"; string subdirectory = Path.Combine(directory, directory); isf.CreateDirectory(directory); Assert.True(isf.DirectoryExists(directory), "directory exists"); isf.CreateDirectory(subdirectory); Assert.True(isf.DirectoryExists(subdirectory), "subdirectory exists"); // Can't delete a directory with content Assert.Throws <IsolatedStorageException>(() => isf.DeleteDirectory(directory)); Assert.True(isf.DirectoryExists(directory)); isf.DeleteDirectory(subdirectory); Assert.False(isf.DirectoryExists(subdirectory)); isf.DeleteDirectory(directory); Assert.False(isf.DirectoryExists(directory)); } }
public void DirectoryExists_Existance(PresetScopes scope) { using (var isf = GetPresetScope(scope)) { string root = isf.GetUserRootDirectory(); string directory = "DirectoryExists_Existance"; isf.CreateDirectory(directory); Assert.True(Directory.Exists(Path.Combine(root, directory)), "exists per file.io where expected"); Assert.True(isf.DirectoryExists(directory), "exists per iso"); isf.DeleteDirectory(directory); Assert.False(Directory.Exists(Path.Combine(root, directory)), "doesn't exist per file.io where expected"); Assert.False(isf.DirectoryExists(directory), "doesn't exist per iso"); // Now nested directory = Path.Combine(directory, directory); isf.CreateDirectory(directory); Assert.True(Directory.Exists(Path.Combine(root, directory)), "exists nested per file.io where expected"); Assert.True(isf.DirectoryExists(directory), "exists nested per iso"); isf.DeleteDirectory(directory); Assert.False(Directory.Exists(Path.Combine(root, directory)), "doesn't exist nested per file.io where expected"); Assert.False(isf.DirectoryExists(directory), "doesn't exist nested per iso"); } }
public void CopyFile_CopiesFile(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo", "CopyFile_CopiesFile"); isf.CopyFile("foo", "bar"); Assert.True(isf.FileExists("bar"), "bar exists"); Assert.Equal("CopyFile_CopiesFile", isf.ReadAllText("bar")); string directory = "CopyFile_CopiesFile"; isf.CreateDirectory(directory); // Copy into nested string nestedFile = Path.Combine(directory, "foobar"); isf.CopyFile("foo", nestedFile); Assert.True(isf.FileExists(nestedFile), "nested file exists"); Assert.Equal("CopyFile_CopiesFile", isf.ReadAllText(nestedFile)); // Copy out of nested isf.CopyFile(nestedFile, "outbound"); Assert.True(isf.FileExists("outbound"), "outbound file exists"); Assert.Equal("CopyFile_CopiesFile", isf.ReadAllText("outbound")); } }
public void MoveFile_MovesFile(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo", "MoveFile_MovesFile"); isf.MoveFile("foo", "bar"); Assert.True(isf.FileExists("bar"), "bar exists"); Assert.Equal("MoveFile_MovesFile", isf.ReadAllText("bar")); Assert.False(isf.FileExists("foo"), "foo doesn't exist"); string directory = "MoveFile_MovesFile"; isf.CreateDirectory(directory); // Move into nested string nestedFile = Path.Combine(directory, "foobar"); isf.MoveFile("bar", nestedFile); Assert.True(isf.FileExists(nestedFile), "nested file exists"); Assert.Equal("MoveFile_MovesFile", isf.ReadAllText(nestedFile)); Assert.False(isf.FileExists("bar"), "bar doesn't exist"); // Move out of nested isf.MoveFile(nestedFile, "outbound"); Assert.True(isf.FileExists("outbound")); Assert.Equal("MoveFile_MovesFile", isf.ReadAllText("outbound")); Assert.False(isf.FileExists(nestedFile), "nested file doesn't exist"); } }
public void ContainsUnknownFiles_CleanStore(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { Assert.False((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { isf.GetUserRootDirectory() })); } }
public void DeleteDirectory_DeletesDirectory(PresetScopes scope) { using (var isf = GetPresetScope(scope)) { isf.CreateDirectory("DeleteDirectory_DeletesDirectory"); Assert.True(isf.DirectoryExists("DeleteDirectory_DeletesDirectory")); isf.DeleteDirectory("DeleteDirectory_DeletesDirectory"); Assert.False(isf.DirectoryExists("DeleteDirectory_DeletesDirectory")); } }
public void MoveFile_MoveOver(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo"); isf.CreateTestFile("bar"); Assert.Throws<IsolatedStorageException>(() => isf.MoveFile("foo", "bar")); } }
public async Task DisposeAsync_MultipleInvokes_Idempotent(PresetScopes scope) { TestHelper.WipeStores(); using (IsolatedStorageFile isf = GetPresetScope(scope)) { IsolatedStorageFileStream isfs = isf.CreateFile("DisposeAsyncFile"); await isfs.DisposeAsync(); await isfs.DisposeAsync(); } }
public void MoveFile_MoveOver(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo"); isf.CreateTestFile("bar"); Assert.Throws <IsolatedStorageException>(() => isf.MoveFile("foo", "bar")); } }
public void ContainsUnknownFiles_NotOkDirectory(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string rootDirectory = isf.GetIdentityRootDirectory(); string otherDirectory = Path.Combine(rootDirectory, "ContainsUnknownFiles_NotOkDirectory"); Directory.CreateDirectory(otherDirectory); Assert.True((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "other directory not ok"); } }
public void RemoveStoreWithContent(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateDirectory("RemoveStoreWithContent_Dir"); using (isf.CreateFile("RemoveStoreWithContent_File")) { }; string root = isf.GetUserRootDirectory(); isf.Remove(); Assert.False(Directory.Exists(root)); } }
public void DeleteFile_DeletesFile(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("DeleteFile_DeletesFile"); Assert.True(isf.FileExists("DeleteFile_DeletesFile")); isf.DeleteFile("DeleteFile_DeletesFile"); Assert.False(isf.FileExists("DeleteFile_DeletesFile")); } }
public void CopyFile_CopyOver(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo", "CopyFile_CopyOver_Foo"); isf.CreateTestFile("bar", "CopyFile_CopyOver_Bar"); Assert.Throws<IsolatedStorageException>(() => isf.CopyFile("foo", "bar")); Assert.Throws<IsolatedStorageException>(() => isf.CopyFile("foo", "bar", overwrite: false)); isf.CopyFile("foo", "bar", overwrite: true); Assert.Equal("CopyFile_CopyOver_Foo", isf.ReadAllText("bar")); } }
public void CopyFile_CopyOver(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("foo", "CopyFile_CopyOver_Foo"); isf.CreateTestFile("bar", "CopyFile_CopyOver_Bar"); Assert.Throws <IsolatedStorageException>(() => isf.CopyFile("foo", "bar")); Assert.Throws <IsolatedStorageException>(() => isf.CopyFile("foo", "bar", overwrite: false)); isf.CopyFile("foo", "bar", overwrite: true); Assert.Equal("CopyFile_CopyOver_Foo", isf.ReadAllText("bar")); } }
public static IsolatedStorageFile GetPresetScope(PresetScopes scope) { switch (scope) { case PresetScopes.UserStoreForApplication: return IsolatedStorageFile.GetUserStoreForApplication(); case PresetScopes.UserStoreForAssembly: return IsolatedStorageFile.GetUserStoreForAssembly(); case PresetScopes.UserStoreForDomain: return IsolatedStorageFile.GetUserStoreForDomain(); default: throw new InvalidOperationException("Unknown preset scope"); } }
public async Task DisposeAsync_FlushesAndCloses(PresetScopes scope) { TestHelper.WipeStores(); using (IsolatedStorageFile isf = GetPresetScope(scope)) { IsolatedStorageFileStream isfs = isf.CreateFile("DisposeAsyncFile"); isfs.Write(new byte[100], 0, 100); await isfs.DisposeAsync(); using (isfs = isf.OpenFile("DisposeAsyncFile", FileMode.Open)) { Assert.Equal(100, isfs.Length); } } }
public void DeleteFile_DeletesFile(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { using (var stream = isf.OpenFile("DeleteFile_DeletesFile", FileMode.Create)) { } Assert.True(isf.FileExists("DeleteFile_DeletesFile")); isf.DeleteFile("DeleteFile_DeletesFile"); Assert.False(isf.FileExists("DeleteFile_DeletesFile")); } }
public void CreateDirectory_Existance(PresetScopes scope) { using (var isf = GetPresetScope(scope)) { string directory = "CreateDirectory_Existance"; string subdirectory = Path.Combine(directory, "Subdirectory"); isf.CreateDirectory(directory); Assert.True(isf.DirectoryExists(directory), "directory exists"); isf.CreateDirectory(subdirectory); Assert.True(isf.DirectoryExists(subdirectory), "nested directory exists"); isf.DeleteDirectory(subdirectory); Assert.False(isf.DirectoryExists(subdirectory), "directory removed"); isf.DeleteDirectory(directory); Assert.False(isf.DirectoryExists(directory), "nested directory removed"); } }
public void CreateFile_Existence(PresetScopes scope) { using (var isf = GetPresetScope(scope)) { string file = "CreateFile_Existence"; string subdirectory = "CreateFile_Existence_Subdirectory"; using (isf.CreateFile(file)) { } Assert.True(isf.FileExists(file), "file exists"); isf.CreateDirectory(subdirectory); Assert.True(isf.DirectoryExists(subdirectory), "directory exists"); string nestedFile = Path.Combine(subdirectory, file); using (isf.CreateFile(nestedFile)) { } Assert.True(isf.FileExists(nestedFile), "nested file exists"); } }
public void ContainsUnknownFiles_OkFiles(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string rootDirectory = isf.GetIdentityRootDirectory(); string identityFile = Path.Combine(rootDirectory, "identity.dat"); string quotaFile = Path.Combine(rootDirectory, "info.dat"); using (File.OpenWrite(identityFile)) { } Assert.False((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "identity ok"); File.Move(identityFile, quotaFile); Assert.False((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "quota ok"); using (File.OpenWrite(identityFile)) { } Assert.False((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "both ok"); } }
public void GetFileNames_GetsFileNames(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateTestFile("A"); isf.CreateTestFile("B"); isf.CreateDirectory("C"); isf.CreateTestFile(Path.Combine("C", "D")); isf.CreateTestFile(Path.Combine("C", "E")); Assert.Equal(new string[] { "A", "B" }, isf.GetFileNames().OrderBy(s => s)); Assert.Equal(new string[] { "A", "B" }, isf.GetFileNames("*").OrderBy(s => s)); Assert.Equal(new string[] { "A" }, isf.GetFileNames("A")); Assert.Equal(new string[] { "D", "E" }, isf.GetFileNames(Path.Combine("C", "*")).OrderBy(s => s)); Assert.Equal(new string[] { "D" }, isf.GetFileNames(Path.Combine("C", "D"))); } }
public void DeleteDirectory_CannotDeleteWithContent(PresetScopes scope) { TestHelper.WipeStores(); // Validating that we aren't passing recursive:true using (var isf = GetPresetScope(scope)) { string directory = "DeleteDirectory_CannotDeleteWithContent"; isf.CreateDirectory(directory); Assert.True(isf.DirectoryExists(directory), "directory exists"); string testFile = Path.Combine(directory, "content.file"); isf.CreateTestFile(testFile); Assert.Throws <IsolatedStorageException>(() => isf.DeleteDirectory(directory)); isf.DeleteFile(testFile); isf.DeleteDirectory(directory); Assert.False(isf.DirectoryExists(directory)); } }
public void OpenFile_Existence(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string file = "OpenFile_Existence"; string subdirectory = "OpenFile_Existence_Subdirectory"; using (isf.OpenFile(file, FileMode.CreateNew)) { } Assert.True(isf.FileExists(file), "file exists"); isf.CreateDirectory(subdirectory); Assert.True(isf.DirectoryExists(subdirectory), "directory exists"); string nestedFile = Path.Combine(subdirectory, file); using (isf.OpenFile(nestedFile, FileMode.CreateNew)) { } Assert.True(isf.FileExists(nestedFile), "nested file exists"); } }
public void ContainsUnknownFiles_NotOkFiles(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { string rootDirectory = isf.GetIdentityRootDirectory(); string otherFile = Path.Combine(rootDirectory, "ContainsUnknownFiles_NotOkFiles"); string identityFile = Path.Combine(rootDirectory, "identity.dat"); string quotaFile = Path.Combine(rootDirectory, "info.dat"); using (File.OpenWrite(otherFile)) { } Assert.True((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "other file not ok"); using (File.OpenWrite(identityFile)) { } Assert.True((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "other file with identity not ok"); File.Move(identityFile, quotaFile); Assert.True((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "other file with quota not ok"); using (File.OpenWrite(identityFile)) { } Assert.True((bool)s_containsUnknownFilesMethod.Invoke(isf, new object[] { rootDirectory }), "too many files not ok"); } }
public void MoveDirectory_MovesDirectory(PresetScopes scope) { TestHelper.WipeStores(); using (var isf = GetPresetScope(scope)) { isf.CreateDirectory("foo"); isf.CreateTestFile(Path.Combine("foo", "foofile"), "MoveDirectory_MovesDirectory"); isf.MoveDirectory("foo", "bar"); Assert.True(isf.DirectoryExists("bar"), "bar exists"); Assert.False(isf.DirectoryExists("foo"), "foo doesn't exist"); Assert.Equal("MoveDirectory_MovesDirectory", isf.ReadAllText(Path.Combine("bar", "foofile"))); // Move into nested isf.CreateDirectory("foo"); string nestedDirectory = Path.Combine("foo", "foobar"); isf.MoveDirectory("bar", nestedDirectory); Assert.True(isf.DirectoryExists(nestedDirectory), "nested directory exists"); Assert.Equal("MoveDirectory_MovesDirectory", isf.ReadAllText(Path.Combine(nestedDirectory, "foofile"))); } }
public async Task DisposeAsync_DerivedIsolatedStorageFileStream_DisposeInvoked(PresetScopes scope) { TestHelper.WipeStores(); using (IsolatedStorageFile isf = GetPresetScope(scope)) using (var isfs = new OverridesDisposeIsolatedStorageFileStream("DisposeAsyncFile", FileMode.Create)) { Assert.False(isfs.DisposeInvoked); await isfs.DisposeAsync(); Assert.True(isfs.DisposeInvoked); } }
public void DeleteDirectory_CannotDeleteWithContent(PresetScopes scope) { TestHelper.WipeStores(); // Validating that we aren't passing recursive:true using (var isf = GetPresetScope(scope)) { string directory = "DeleteDirectory_CannotDeleteWithContent"; isf.CreateDirectory(directory); Assert.True(isf.DirectoryExists(directory), "directory exists"); string testFile = Path.Combine(directory, "content.file"); isf.CreateTestFile(testFile); Assert.Throws<IsolatedStorageException>(() => isf.DeleteDirectory(directory)); isf.DeleteFile(testFile); isf.DeleteDirectory(directory); Assert.False(isf.DirectoryExists(directory)); } }