From 073a0201895ab9af996c1b30790fbe3c2ccaa5d0 Mon Sep 17 00:00:00 2001 From: James King Date: Fri, 21 Jun 2024 10:17:48 +0100 Subject: [PATCH] Failing test for watching a SubFileSystem involving case sensitivity Watcher events get silently discarded if all conditions are met: * SubFileSystem was created with incorrect case * Changed file path includes a ~ * Any segment of changed file path is short enough to possibly be a SFN --- .../FileSystems/TestSubFileSystem.cs | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Zio.Tests/FileSystems/TestSubFileSystem.cs b/src/Zio.Tests/FileSystems/TestSubFileSystem.cs index 620789f..d43decf 100644 --- a/src/Zio.Tests/FileSystems/TestSubFileSystem.cs +++ b/src/Zio.Tests/FileSystems/TestSubFileSystem.cs @@ -74,6 +74,43 @@ public void TestWatcher() Assert.True(gotChange); } + [SkippableTheory] + [InlineData("/test", "/test", "/foo.txt")] + [InlineData("/test", "/test", "/~foo.txt")] + [InlineData("/test", "/TEST", "/foo.txt")] + [InlineData("/test", "/TEST", "/~foo.txt")] + [InlineData("/verylongname", "/VERYLONGNAME", "/foo.txt")] + [InlineData("/verylongname", "/VERYLONGNAME", "/~foo.txt")] + public void TestWatcherCaseSensitive(string physicalDir, string subDir, string filePath) + { + Skip.IfNot(IsWindows, "This test involves case insensitivity on Windows"); + + var physicalFs = GetCommonPhysicalFileSystem(); + physicalFs.CreateDirectory(physicalDir); + + Assert.True(physicalFs.DirectoryExists(physicalDir)); + Assert.True(physicalFs.DirectoryExists(subDir)); + + var subFs = new SubFileSystem(physicalFs, subDir); + var watcher = subFs.Watch("/"); + + var gotChange = false; + watcher.Created += (sender, args) => + { + if (args.FullPath == filePath) + { + gotChange = true; + } + }; + + watcher.IncludeSubdirectories = true; + watcher.EnableRaisingEvents = true; + + physicalFs.WriteAllText($"{physicalDir}{filePath}", "test"); + Thread.Sleep(100); + Assert.True(gotChange); + } + [SkippableFact] public void TestDirectorySymlink() {