using System.IO.Abstractions; using System.IO.Abstractions.TestingHelpers; using System.Runtime.InteropServices; using Terminal.Gui; using TerminalGuiFluentTesting; using TerminalGuiFluentTestingXunit; using Xunit.Abstractions; namespace IntegrationTests.FluentTests; public class FileDialogFluentTests { private readonly TextWriter _out; public FileDialogFluentTests (ITestOutputHelper outputHelper) { _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; } [Theory] [ClassData (typeof (V2TestDrivers))] public void CancelFileDialog_UsingEscape (V2TestDriver d) { var sd = new SaveDialog (CreateExampleFileSystem ()); using var c = With.A (sd, 100, 20, d) .ScreenShot ("Save dialog", _out) .Escape () .Then (() => Assert.True (sd.Canceled)) .Stop (); } [Theory] [ClassData (typeof (V2TestDrivers))] public void CancelFileDialog_UsingCancelButton_TabThenEnter (V2TestDriver d) { var sd = new SaveDialog (CreateExampleFileSystem ()) { Modal = false }; using var c = With.A (sd, 100, 20, d) .ScreenShot ("Save dialog", _out) .Focus