Skip to content

Commit 4fc503d

Browse files
committed
add filesystem unicode mount regression test
1 parent 13bc26f commit 4fc503d

File tree

3 files changed

+100
-10
lines changed

3 files changed

+100
-10
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections.Generic;
2+
3+
namespace ManagedCode.Storage.Tests.VirtualFileSystem;
4+
5+
public static class UnicodeVfsTestCases
6+
{
7+
public static IEnumerable<object[]> FolderScenarios => new[]
8+
{
9+
new object[] { "Українська-папка", "лист-привіт", "Привіт з Києва!" },
10+
new object[] { "中文目錄", "測試文件", "雲端中的內容" },
11+
new object[] { "日本語ディレクトリ", "テストファイル", "東京からこんにちは" },
12+
new object[] { "한국어_폴더", "테스트-파일", "부산에서 안녕하세요" },
13+
new object[] { "emoji📁", "😀-файл", "multi🌐lingual content" }
14+
};
15+
}

Tests/ManagedCode.Storage.Tests/VirtualFileSystem/VirtualFileSystemTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ protected VirtualFileSystemTests(TFixture fixture)
2929
private Task<VirtualFileSystemTestContext> CreateContextAsync() => _fixture.CreateContextAsync();
3030
private VirtualFileSystemCapabilities Capabilities => _fixture.Capabilities;
3131

32-
public static IEnumerable<object[]> UnicodeFolderTestCases => new[]
33-
{
34-
new object[] { "Українська-папка", "лист-привіт", "Привіт з Києва!" },
35-
new object[] { "中文目錄", "測試文件", "雲端中的內容" },
36-
new object[] { "日本語ディレクトリ", "テストファイル", "東京からこんにちは" },
37-
new object[] { "한국어_폴더", "테스트-파일", "부산에서 안녕하세요" },
38-
new object[] { "emoji📁", "😀-файл", "multi🌐lingual content" }
39-
};
40-
4132
[Fact]
4233
public async Task WriteAndReadFile_ShouldRoundtrip()
4334
{
@@ -188,7 +179,7 @@ await file.SetMetadataAsync(new Dictionary<string, string>
188179
}
189180

190181
[Theory]
191-
[MemberData(nameof(UnicodeFolderTestCases))]
182+
[MemberData(nameof(UnicodeVfsTestCases.FolderScenarios), MemberType = typeof(UnicodeVfsTestCases))]
192183
public async Task WriteAndReadFile_WithUnicodeDirectories_ShouldRoundtrip(
193184
string directoryName,
194185
string fileName,

0 commit comments

Comments
 (0)