public void AsyncOpen() { #region Create File (TODO: create as reuseable method byte[] buffer = new byte[1024]; IFileSystem fileSystem = new Buttercup.Control.Common.IO.InMemoryFileSystem(); // Should create the directory aswell Stream targetStream; IFile file; // Wrap in using to test that we can still open the file's stream after it // has been disposed. using (targetStream = fileSystem.CreateFile("Books/Test.txt")) { file = fileSystem.GetFile("Books/Test.txt"); Assert.IsTrue(file.Exists); // Write the contents of this file to the new file StreamResourceInfo info = App.GetResourceStream(new Uri(@"Control.Common.Tests;component/Files/File1.txt", UriKind.Relative)); Stream sourceStream = info.Stream; while (true) { int count = sourceStream.Read(buffer, 0, buffer.Length); if (count > 0) { targetStream.Write(buffer, 0, count); } else { break; } } } #endregion file = fileSystem.GetFile("Books/Test.txt"); file.OpenAsyncComplete +=new EventHandler<DownloadCompleteEventArgs>(file_OpenAsyncComplete); //+= new EventHandler<DownloadCompleteEventArgs>(file_OpenAsyncComplete); file.OpenAsync(); Assert.IsTrue(true); }
public void CreateAndWriteToFile() { byte[] buffer = new byte[1024]; IFileSystem fileSystem = new Buttercup.Control.Common.IO.InMemoryFileSystem(); // Should create the directory aswell Stream targetStream; IFile file; // Wrap in using to test that we can still open the file's stream after it // has been disposed. using (targetStream = fileSystem.CreateFile("Books/Test.txt")) { file = fileSystem.GetFile("Books/Test.txt"); Assert.IsTrue(file.Exists); // Write the contents of this file to the new file StreamResourceInfo info = App.GetResourceStream(new Uri(@"Control.Common.Tests;component/Files/File1.txt", UriKind.Relative)); Stream sourceStream = info.Stream; while (true) { int count = sourceStream.Read(buffer, 0, buffer.Length); if (count > 0) { targetStream.Write(buffer, 0, count); } else { break; } } } // Get the file again and make sure it has the same contents. file = fileSystem.GetFile("Books/Test.txt"); Stream fileStream = file.Open(FileMode.Open); StreamReader reader = new StreamReader(fileStream); Assert.IsTrue(reader.ReadToEnd() == "This is a test file to load into the InMemoryFileSystem for testing purposes."); }
public void DeleteFolders() { IFileSystem fileSystem = new Buttercup.Control.Common.IO.InMemoryFileSystem(); fileSystem.CreateDirectory("Books"); fileSystem.CreateFile("Books/File1.txt"); fileSystem.DeleteDirectory("Books"); IDirectory directory = fileSystem.GetDirectory("Books"); IFile file = fileSystem.GetFile("Books/File1.txt"); Assert.IsTrue(!directory.Exists && !file.Exists); }
public void DeleteFiles() { IFileSystem fileSystem = new Buttercup.Control.Common.IO.InMemoryFileSystem(); fileSystem.CreateDirectory("Books"); fileSystem.CreateFile("Books/File1.txt"); fileSystem.CreateFile("Books/File2.txt"); fileSystem.CreateFile("Books/File3.txt"); fileSystem.CreateFile("Books/File4.txt"); int fileCount1 = fileSystem.GetDirectory("Books").GetFiles().Count; IFile file = fileSystem.GetFile("Books/File3.txt"); file.Delete(); int fileCount2 = fileSystem.GetDirectory("Books").GetFiles().Count; Assert.IsTrue(fileCount1 == 4 && fileCount2 == 3); }