using System.Globalization; using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using System.Runtime.InteropServices; using TerminalGuiFluentTesting; using TerminalGuiFluentTestingXunit; using Xunit.Abstractions; namespace IntegrationTests.FluentTests; public class FileDialogFluentTests { private readonly TextWriter _out; public FileDialogFluentTests (ITestOutputHelper outputHelper) { CultureInfo.CurrentUICulture = CultureInfo.InvariantCulture; _out = new TestOutputWriter (outputHelper); } private MockFileSystem CreateExampleFileSystem () { // Optional: use Ordinal to simulate Linux-style case sensitivity var mockFileSystem = new MockFileSystem (new Dictionary ()); string testDir = mockFileSystem.Path.Combine ("test-dir"); string subDir = mockFileSystem.Path.Combine (testDir, "sub-dir"); string logsDir = "logs"; string emptyDir = "empty-dir"; // Add files mockFileSystem.AddFile (mockFileSystem.Path.Combine (testDir, "file1.txt"), new MockFileData ("Hello, this is file 1.")); mockFileSystem.AddFile (mockFileSystem.Path.Combine (testDir, "file2.txt"), new MockFileData ("Hello, this is file 2.")); mockFileSystem.AddFile (mockFileSystem.Path.Combine (subDir, "nested-file.txt"), new MockFileData ("This is a nested file.")); mockFileSystem.AddFile (mockFileSystem.Path.Combine (logsDir, "log1.log"), new MockFileData ("Log entry 1")); mockFileSystem.AddFile (mockFileSystem.Path.Combine (logsDir, "log2.log"), new MockFileData ("Log entry 2")); // Create an empty directory mockFileSystem.AddDirectory (emptyDir); return mockFileSystem; } private Toplevel NewSaveDialog (out SaveDialog sd, bool modal = true) { return NewSaveDialog (out sd, out _, modal); } private Toplevel NewSaveDialog (out SaveDialog sd, out MockFileSystem fs, bool modal = true) { fs = CreateExampleFileSystem (); sd = new SaveDialog (fs) { Modal = modal }; return sd; } [Theory] [ClassData (typeof (TestDrivers))] public void CancelFileDialog_QuitKey_Quits (TestDriver d) { SaveDialog? sd = null; using GuiTestContext c = With.A (() => NewSaveDialog (out sd), 100, 20, d, logWriter: _out) .ScreenShot ("Save dialog", _out) .EnqueueKeyEvent (Application.QuitKey) .AssertTrue (sd!.Canceled); } [Theory] [ClassData (typeof (TestDrivers))] public void CancelFileDialog_UsingCancelButton_TabThenEnter (TestDriver d) { SaveDialog? sd = null; using var c = With.A (() => NewSaveDialog (out sd, modal: false), 100, 20, d) .ScreenShot ("Save dialog", _out) .Focus