public async Task DesktopStorageReadFile() { // Arrange IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); string result; // Act using (Stream stream = await container.GetFileStreamAsync("TestFile1.txt")) { var buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int)stream.Length); result = Encoding.UTF8.GetString(buffer); } // Assert Assert.NotNull(result); Assert.Equal("This is test file 1.", result); }
public async Task DesktopStorageWriteReadDeleteFile() { // Arrange IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); const string text = "This is R/W test"; const string fileName = "rw.txt"; var memStream = new MemoryStream(); var writer = new StreamWriter(memStream); writer.Write(text); writer.Flush(); memStream.Position = 0; string result; // Act await container.WriteFileAsync(memStream, fileName); using (Stream stream = await container.GetFileStreamAsync(fileName)) { var buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int)stream.Length); result = Encoding.UTF8.GetString(buffer); } await container.DeleteFileAsync(fileName); var files = await container.GetFilesAsync("", StorageSearchOption.Default); // Assert Assert.NotNull(result); Assert.Equal(text, result); Assert.False(files.Any(d => string.Equals(d, fileName, StringComparison.OrdinalIgnoreCase))); }