|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.IO; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using ManagedCode.Storage.FileSystem; |
| 6 | +using ManagedCode.Storage.FileSystem.Options; |
| 7 | +using ManagedCode.Storage.Tests.VirtualFileSystem.Fixtures; |
| 8 | +using ManagedCode.Storage.VirtualFileSystem.Core; |
| 9 | +using ManagedCode.Storage.VirtualFileSystem.Options; |
| 10 | +using Shouldly; |
| 11 | +using Xunit; |
| 12 | + |
| 13 | +namespace ManagedCode.Storage.Tests.VirtualFileSystem; |
| 14 | + |
| 15 | +[Collection(VirtualFileSystemCollection.Name)] |
| 16 | +public sealed class FileSystemVirtualFileSystemUnicodeMountTests |
| 17 | +{ |
| 18 | + [Theory] |
| 19 | + [MemberData(nameof(UnicodeVfsTestCases.FolderScenarios), MemberType = typeof(UnicodeVfsTestCases))] |
| 20 | + public async Task MountingExistingUnicodeDirectories_ShouldExposeFiles( |
| 21 | + string directoryName, |
| 22 | + string fileName, |
| 23 | + string content) |
| 24 | + { |
| 25 | + var rootFolder = Path.Combine(Path.GetTempPath(), "managedcode-vfs-existing", Guid.NewGuid().ToString("N")); |
| 26 | + var internationalFolder = Path.Combine(rootFolder, "international", directoryName); |
| 27 | + Directory.CreateDirectory(internationalFolder); |
| 28 | + |
| 29 | + var seededFilePath = Path.Combine(internationalFolder, $"{fileName}.txt"); |
| 30 | + await File.WriteAllTextAsync(seededFilePath, content); |
| 31 | + |
| 32 | + var options = new FileSystemStorageOptions |
| 33 | + { |
| 34 | + BaseFolder = rootFolder, |
| 35 | + CreateContainerIfNotExists = true |
| 36 | + }; |
| 37 | + |
| 38 | + var storage = new FileSystemStorage(options); |
| 39 | + |
| 40 | + async ValueTask Cleanup() |
| 41 | + { |
| 42 | + try |
| 43 | + { |
| 44 | + await storage.RemoveContainerAsync(); |
| 45 | + } |
| 46 | + finally |
| 47 | + { |
| 48 | + if (Directory.Exists(rootFolder)) |
| 49 | + { |
| 50 | + Directory.Delete(rootFolder, recursive: true); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + await using var context = await VirtualFileSystemTestContext.CreateAsync( |
| 56 | + storage, |
| 57 | + containerName: string.Empty, |
| 58 | + ownsStorage: true, |
| 59 | + serviceProvider: null, |
| 60 | + cleanup: Cleanup); |
| 61 | + |
| 62 | + var vfs = context.FileSystem; |
| 63 | + var expectedPath = new VfsPath($"/international/{directoryName}/{fileName}.txt"); |
| 64 | + |
| 65 | + (await vfs.FileExistsAsync(expectedPath)).ShouldBeTrue(); |
| 66 | + |
| 67 | + var file = await vfs.GetFileAsync(expectedPath); |
| 68 | + var actualContent = await file.ReadAllTextAsync(); |
| 69 | + actualContent.ShouldBe(content); |
| 70 | + |
| 71 | + var entries = new List<IVfsNode>(); |
| 72 | + await foreach (var entry in vfs.ListAsync(new VfsPath($"/international/{directoryName}"), new ListOptions |
| 73 | + { |
| 74 | + IncludeDirectories = false, |
| 75 | + IncludeFiles = true, |
| 76 | + Recursive = false |
| 77 | + })) |
| 78 | + { |
| 79 | + entries.Add(entry); |
| 80 | + } |
| 81 | + |
| 82 | + entries.ShouldContain(e => e.Path.Value == expectedPath.Value); |
| 83 | + } |
| 84 | +} |
0 commit comments