public async Task DesktopStorageGetFilesList() { // Arrange IStorage storage = new FileSystemStorage(this._storagePath); IStorageContainer container = await storage.GetContainerAsync(DesktopStorageContainerTests._precreatedContainerName); // Act var files = await container.GetFilesAsync("", StorageSearchOption.AllDirectories | StorageSearchOption.StripPaths); var filesFull = await container.GetFilesAsync("", StorageSearchOption.AllDirectories); // Assert Assert.NotNull(files); Assert.NotNull(filesFull); Assert.True(files.Any()); Assert.True(filesFull.Any()); }
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))); }