public virtual async Task CanGetFileListForSingleFolderAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { await storage.SaveFileContentsAsync(@"archived\archived.txt", "archived"); await storage.SaveFileContentsAsync(@"q\new.txt", "new"); await storage.SaveFileContentsAsync(@"long/path/in/here/1.hey.stuff-2.json", "archived"); Assert.Equal(3, (await FileStorageExtensions.GetFileInformationsAsync(storage)).Count()); Assert.Single(await storage.GetFileInformationsAsync(limit: 1)); Assert.Single(await storage.GetFileInformationsAsync(@"long\path\in\here\*stuff*.json")); Assert.Single(await storage.GetFileInformationsAsync(@"archived\*")); Assert.Equal("archived", await storage.GetFileContentsAsync(@"archived\archived.txt")); Assert.Single(await storage.GetFileInformationsAsync(@"q\*")); Assert.Equal("new", await storage.GetFileContentsAsync(@"q\new.txt")); } }
public virtual async Task CanDeleteNestedFolderAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { await storage.SaveFileContentsAsync(@"x\hello.txt", "hello"); await storage.SaveFileContentsAsync(@"x\nested\world.csv", "nested world"); await storage.SaveFileContentsAsync(@"x\nested\hello.txt", "nested hello"); Assert.Equal(3, (await FileStorageExtensions.GetFileInformationsAsync(storage)).Count()); Assert.Single(await storage.GetFileInformationsAsync(limit: 1)); Assert.Equal(3, (await storage.GetFileInformationsAsync(@"x\*")).Count()); Assert.Equal(2, (await storage.GetFileInformationsAsync(@"x\nested\*")).Count()); Assert.Equal(2, (await storage.GetFileInformationsAsync(@"x\*.txt")).Count()); await storage.DeleteFilesAsync(@"x\nested"); Assert.Single(await FileStorageExtensions.GetFileInformationsAsync(storage)); Assert.True(await storage.ExistsAsync(@"x\hello.txt")); Assert.False(await storage.ExistsAsync(@"x\nested\hello.txt")); Assert.False(await storage.ExistsAsync(@"x\nested\world.csv")); } }
public virtual async Task CanSaveFilesWithSerializerAsync(ISerializer serializer, string fileExtension) { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { var path = $"entity-{Guid.NewGuid().ToString("N").Substring(10)}.{fileExtension}"; Assert.False(await storage.ExistsAsync(path)); var entity = new StubEntity { FirstName = "John", LastName = "Doe" }; var saveResult = await storage.SaveFileObjectAsync(path, entity, serializer); // write Assert.True(saveResult); Assert.Single(await FileStorageExtensions.GetFileInformationsAsync(storage)); Assert.True(await storage.ExistsAsync(path)); var getResult = await storage.GetFileObjectAsync <StubEntity>(path, serializer); // read Assert.Equal("John", getResult.FirstName); Assert.Equal("Doe", getResult.LastName); } }
public virtual async Task CanSaveFilesAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { var path = $"test-{Guid.NewGuid().ToString("N").Substring(10)}.txt"; Assert.False(await storage.ExistsAsync(path)); using (var stream = StreamHelper.ToStream("test data")) { var result = await storage.SaveFileAsync(path, stream); // write Assert.True(result); } Assert.Single(await FileStorageExtensions.GetFileInformationsAsync(storage)); Assert.True(await storage.ExistsAsync(path)); using (var stream = await storage.GetFileStreamAsync(path)) // read { var result = await new StreamReader(stream).ReadToEndAsync(); Assert.Equal("test data", result); } } }
public virtual async Task CanRenameFilesAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { var path1 = $"test-{Guid.NewGuid().ToString("N").Substring(10)}.txt"; var path2 = $"test-{Guid.NewGuid().ToString("N").Substring(10)}.txt"; Assert.True(await storage.SaveFileContentsAsync(path1, "test")); Assert.True(await storage.RenameFileAsync(path1, @"archive\new.txt")); Assert.Equal("test", await storage.GetFileContentsAsync(@"archive\new.txt")); Assert.Single(await FileStorageExtensions.GetFileInformationsAsync(storage)); Assert.True(await storage.SaveFileContentsAsync(path2, "test2")); Assert.True(await storage.RenameFileAsync(path2, @"archive\new.txt")); Assert.Equal("test2", await storage.GetFileContentsAsync(@"archive\new.txt")); Assert.Single(await FileStorageExtensions.GetFileInformationsAsync(storage)); } }
public virtual async Task CanManageFilesAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { var path1 = $"test-{Guid.NewGuid().ToString("N").Substring(10)}.txt"; var path2 = $"test-{Guid.NewGuid().ToString("N").Substring(10)}.txt"; await storage.SaveFileContentsAsync(path1, "test"); var file = (await FileStorageExtensions.GetFileInformationsAsync(storage)).Single(); Assert.NotNull(file); Assert.Equal(path1, file.Path); var content = await storage.GetFileContentsAsync(path1); Assert.Equal("test", content); await storage.RenameFileAsync(path1, path2); Assert.Contains(await FileStorageExtensions.GetFileInformationsAsync(storage), f => f.Path == path2); await storage.DeleteFileAsync(path2); Assert.Empty(await FileStorageExtensions.GetFileInformationsAsync(storage)); } }
protected async Task ResetAsync() { var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { var files = (await FileStorageExtensions.GetFileInformationsAsync(storage)).ToList(); if (files.Count > 0) { await storage.DeleteFilesAsync(files); } Assert.Empty(await FileStorageExtensions.GetFileInformationsAsync(storage)); } }
public virtual async Task CanDeleteEntireFolderAsync() { await this.ResetAsync(); var storage = this.GetStorage(); if (storage == null) { return; } using (storage) { await storage.SaveFileContentsAsync(@"x\hello.txt", "hello"); await storage.SaveFileContentsAsync(@"x\nested\world.csv", "nested world"); Assert.Equal(2, (await FileStorageExtensions.GetFileInformationsAsync(storage)).Count()); await storage.DeleteFilesAsync(@"x"); Assert.Empty(await FileStorageExtensions.GetFileInformationsAsync(storage)); } }