FileDialogTests.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. using System.IO.Abstractions.TestingHelpers;
  2. using System.Runtime.InteropServices;
  3. using Xunit.Abstractions;
  4. namespace Terminal.Gui.FileServicesTests;
  5. public class FileDialogTests (ITestOutputHelper output)
  6. {
  7. [Theory]
  8. [InlineData (true)]
  9. [InlineData (false)]
  10. [AutoInitShutdown]
  11. public void CancelSelection (bool cancel)
  12. {
  13. FileDialog dlg = GetInitializedFileDialog ();
  14. string openIn = Path.Combine (Environment.CurrentDirectory, "zz");
  15. Directory.CreateDirectory (openIn);
  16. dlg.Path = openIn + Path.DirectorySeparatorChar;
  17. dlg.FilesSelected += (s, e) => e.Cancel = cancel;
  18. //pressing enter will complete the current selection
  19. // unless the event cancels the confirm
  20. Send ('\n', ConsoleKey.Enter);
  21. Assert.Equal (cancel, dlg.Canceled);
  22. dlg.Dispose ();
  23. }
  24. [Fact]
  25. [AutoInitShutdown]
  26. public void DirectTyping_Allowed ()
  27. {
  28. FileDialog dlg = GetInitializedFileDialog ();
  29. TextField tf = dlg.Subviews.OfType<TextField> ().First (t => t.HasFocus);
  30. tf.ClearAllSelection ();
  31. tf.CursorPosition = tf.Text.Length;
  32. Assert.True (tf.HasFocus);
  33. SendSlash ();
  34. Assert.Equal (
  35. new DirectoryInfo (Environment.CurrentDirectory + Path.DirectorySeparatorChar).FullName,
  36. new DirectoryInfo (dlg.Path + Path.DirectorySeparatorChar).FullName
  37. );
  38. // continue typing the rest of the path
  39. Send ("BOB");
  40. Send ('.', ConsoleKey.OemPeriod);
  41. Send ("CSV");
  42. Assert.True (dlg.Canceled);
  43. Send ('\n', ConsoleKey.Enter);
  44. Assert.False (dlg.Canceled);
  45. Assert.Equal ("bob.csv", Path.GetFileName (dlg.Path));
  46. dlg.Dispose ();
  47. }
  48. [Fact]
  49. [AutoInitShutdown]
  50. public void DirectTyping_AutoComplete ()
  51. {
  52. FileDialog dlg = GetInitializedFileDialog ();
  53. string openIn = Path.Combine (Environment.CurrentDirectory, "zz");
  54. Directory.CreateDirectory (openIn);
  55. string expectedDest = Path.Combine (openIn, "xx");
  56. Directory.CreateDirectory (expectedDest);
  57. dlg.Path = openIn + Path.DirectorySeparatorChar;
  58. Send ("X");
  59. // nothing selected yet
  60. Assert.True (dlg.Canceled);
  61. Assert.Equal ("x", Path.GetFileName (dlg.Path));
  62. // complete auto typing
  63. Send ('\t', ConsoleKey.Tab);
  64. // but do not close dialog
  65. Assert.True (dlg.Canceled);
  66. Assert.EndsWith ("xx" + Path.DirectorySeparatorChar, dlg.Path);
  67. // press enter again to confirm the dialog
  68. Send ('\n', ConsoleKey.Enter);
  69. Assert.False (dlg.Canceled);
  70. Assert.EndsWith ("xx" + Path.DirectorySeparatorChar, dlg.Path);
  71. dlg.Dispose ();
  72. }
  73. [Fact]
  74. [AutoInitShutdown]
  75. public void DoNotConfirmSelectionWhenFindFocused ()
  76. {
  77. FileDialog dlg = GetInitializedFileDialog ();
  78. string openIn = Path.Combine (Environment.CurrentDirectory, "zz");
  79. Directory.CreateDirectory (openIn);
  80. dlg.Path = openIn + Path.DirectorySeparatorChar;
  81. #if BROKE_IN_2927
  82. Send ('f', ConsoleKey.F, false, true, false);
  83. #else
  84. Application.OnKeyDown (Key.Tab);
  85. Application.OnKeyDown (Key.Tab);
  86. Application.OnKeyDown (Key.Tab);
  87. #endif
  88. Assert.IsType<TextField> (dlg.MostFocused);
  89. var tf = (TextField)dlg.MostFocused;
  90. Assert.Equal ("Enter Search", tf.Caption);
  91. // Dialog has not yet been confirmed with a choice
  92. Assert.True (dlg.Canceled);
  93. //pressing enter while search focused should not confirm path
  94. Send ('\n', ConsoleKey.Enter);
  95. Assert.True (dlg.Canceled);
  96. // tabbing out of search
  97. Send ('\t', ConsoleKey.Tab);
  98. //should allow enter to confirm path
  99. Send ('\n', ConsoleKey.Enter);
  100. // Dialog has not yet been confirmed with a choice
  101. Assert.False (dlg.Canceled);
  102. dlg.Dispose ();
  103. }
  104. [Fact]
  105. [AutoInitShutdown]
  106. public void DotDot_MovesToRoot_ThenPressBack ()
  107. {
  108. FileDialog dlg = GetDialog ();
  109. dlg.OpenMode = OpenMode.Directory;
  110. dlg.AllowsMultipleSelection = true;
  111. var selected = false;
  112. dlg.FilesSelected += (s, e) => { selected = true; };
  113. AssertIsTheStartingDirectory (dlg.Path);
  114. Assert.IsType<TextField> (dlg.MostFocused);
  115. Send ('v', ConsoleKey.DownArrow);
  116. Assert.IsType<TableView> (dlg.MostFocused);
  117. // ".." should be the first thing selected
  118. // ".." should not mess with the displayed path
  119. AssertIsTheStartingDirectory (dlg.Path);
  120. // Accept navigation up a directory
  121. Send ('\n', ConsoleKey.Enter);
  122. AssertIsTheRootDirectory (dlg.Path);
  123. Assert.True (dlg.Canceled);
  124. Assert.False (selected);
  125. // Now press the back button (in table view)
  126. Send ('<', ConsoleKey.Backspace);
  127. // Should move us back to the root
  128. AssertIsTheStartingDirectory (dlg.Path);
  129. Assert.True (dlg.Canceled);
  130. Assert.False (selected);
  131. dlg.Dispose ();
  132. }
  133. [Theory]
  134. [AutoInitShutdown]
  135. [InlineData (true)]
  136. [InlineData (false)]
  137. public void MultiSelectDirectory_CannotToggleDotDot (bool acceptWithEnter)
  138. {
  139. FileDialog dlg = GetDialog ();
  140. dlg.OpenMode = OpenMode.Directory;
  141. dlg.AllowsMultipleSelection = true;
  142. IReadOnlyCollection<string> eventMultiSelected = null;
  143. dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
  144. Assert.IsType<TextField> (dlg.MostFocused);
  145. Send ('v', ConsoleKey.DownArrow);
  146. Assert.IsType<TableView> (dlg.MostFocused);
  147. // Try to toggle '..'
  148. Send (' ', ConsoleKey.Spacebar);
  149. Send ('v', ConsoleKey.DownArrow);
  150. // Toggle subfolder
  151. Send (' ', ConsoleKey.Spacebar);
  152. Assert.True (dlg.Canceled);
  153. if (acceptWithEnter)
  154. {
  155. Send ('\n', ConsoleKey.Enter);
  156. }
  157. else
  158. {
  159. Send ('O', ConsoleKey.O, false, true);
  160. }
  161. Assert.False (dlg.Canceled);
  162. Assert.Multiple (
  163. () =>
  164. {
  165. // Only the subfolder should be selected
  166. Assert.Single (dlg.MultiSelected);
  167. AssertIsTheSubfolder (dlg.Path);
  168. AssertIsTheSubfolder (dlg.MultiSelected.Single ());
  169. },
  170. () =>
  171. {
  172. // Event should also agree with the final state
  173. Assert.NotNull (eventMultiSelected);
  174. Assert.Single (eventMultiSelected);
  175. AssertIsTheSubfolder (eventMultiSelected.Single ());
  176. }
  177. );
  178. dlg.Dispose ();
  179. }
  180. [Theory]
  181. [AutoInitShutdown]
  182. [InlineData (true)]
  183. [InlineData (false)]
  184. public void MultiSelectDirectory_CanToggleThenAccept (bool acceptWithEnter)
  185. {
  186. FileDialog dlg = GetDialog ();
  187. dlg.OpenMode = OpenMode.Directory;
  188. dlg.AllowsMultipleSelection = true;
  189. IReadOnlyCollection<string> eventMultiSelected = null;
  190. dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
  191. Assert.IsType<TextField> (dlg.MostFocused);
  192. Send ('v', ConsoleKey.DownArrow);
  193. Assert.IsType<TableView> (dlg.MostFocused);
  194. // Move selection to subfolder
  195. Send ('v', ConsoleKey.DownArrow);
  196. // Toggle subfolder
  197. Send (' ', ConsoleKey.Spacebar);
  198. Assert.True (dlg.Canceled);
  199. if (acceptWithEnter)
  200. {
  201. Send ('\n', ConsoleKey.Enter);
  202. }
  203. else
  204. {
  205. Send ('O', ConsoleKey.O, false, true);
  206. }
  207. Assert.False (dlg.Canceled);
  208. Assert.Multiple (
  209. () =>
  210. {
  211. // Only the subfolder should be selected
  212. Assert.Single (dlg.MultiSelected);
  213. AssertIsTheSubfolder (dlg.Path);
  214. AssertIsTheSubfolder (dlg.MultiSelected.Single ());
  215. },
  216. () =>
  217. {
  218. // Event should also agree with the final state
  219. Assert.NotNull (eventMultiSelected);
  220. Assert.Single (eventMultiSelected);
  221. AssertIsTheSubfolder (eventMultiSelected.Single ());
  222. }
  223. );
  224. dlg.Dispose ();
  225. }
  226. [Fact]
  227. [AutoInitShutdown]
  228. public void MultiSelectDirectory_EnterOpensFolder ()
  229. {
  230. FileDialog dlg = GetDialog ();
  231. dlg.OpenMode = OpenMode.Directory;
  232. dlg.AllowsMultipleSelection = true;
  233. IReadOnlyCollection<string> eventMultiSelected = null;
  234. dlg.FilesSelected += (s, e) => { eventMultiSelected = e.Dialog.MultiSelected; };
  235. Assert.IsType<TextField> (dlg.MostFocused);
  236. Send ('v', ConsoleKey.DownArrow);
  237. Assert.IsType<TableView> (dlg.MostFocused);
  238. // Move selection to subfolder
  239. Send ('v', ConsoleKey.DownArrow);
  240. Send ('\n', ConsoleKey.Enter);
  241. // Path should update to the newly opened folder
  242. AssertIsTheSubfolder (dlg.Path);
  243. // No selection will have been confirmed
  244. Assert.True (dlg.Canceled);
  245. Assert.Empty (dlg.MultiSelected);
  246. Assert.Null (eventMultiSelected);
  247. dlg.Dispose ();
  248. }
  249. [Fact]
  250. [AutoInitShutdown]
  251. public void OnLoad_TextBoxIsFocused ()
  252. {
  253. FileDialog dlg = GetInitializedFileDialog ();
  254. View tf = dlg.Subviews.FirstOrDefault (t => t.HasFocus);
  255. Assert.NotNull (tf);
  256. Assert.IsType<TextField> (tf);
  257. dlg.Dispose ();
  258. }
  259. [Theory]
  260. [AutoInitShutdown]
  261. [InlineData (true, true)]
  262. [InlineData (true, false)]
  263. [InlineData (false, true)]
  264. [InlineData (false, false)]
  265. public void PickDirectory_ArrowNavigation (bool openModeMixed, bool multiple)
  266. {
  267. FileDialog dlg = GetDialog ();
  268. dlg.OpenMode = openModeMixed ? OpenMode.Mixed : OpenMode.Directory;
  269. dlg.AllowsMultipleSelection = multiple;
  270. Assert.IsType<TextField> (dlg.MostFocused);
  271. Send ('v', ConsoleKey.DownArrow);
  272. Assert.IsType<TableView> (dlg.MostFocused);
  273. // Should be selecting ..
  274. Send ('v', ConsoleKey.DownArrow);
  275. // Down to the directory
  276. Assert.True (dlg.Canceled);
  277. // Alt+O to open (enter would just navigate into the child dir)
  278. Send ('O', ConsoleKey.O, false, true);
  279. Assert.False (dlg.Canceled);
  280. AssertIsTheSubfolder (dlg.Path);
  281. dlg.Dispose ();
  282. }
  283. [Theory]
  284. [AutoInitShutdown]
  285. [InlineData (true, true)]
  286. [InlineData (true, false)]
  287. [InlineData (false, true)]
  288. [InlineData (false, false)]
  289. public void PickDirectory_DirectTyping (bool openModeMixed, bool multiple)
  290. {
  291. FileDialog dlg = GetDialog ();
  292. dlg.OpenMode = openModeMixed ? OpenMode.Mixed : OpenMode.Directory;
  293. dlg.AllowsMultipleSelection = multiple;
  294. // whe first opening the text field will have select all on
  295. // so to add to current path user must press End or right
  296. Send ('>', ConsoleKey.RightArrow);
  297. Send ("SUBFOLDER");
  298. // Dialog has not yet been confirmed with a choice
  299. Assert.True (dlg.Canceled);
  300. // Now it has
  301. Send ('\n', ConsoleKey.Enter);
  302. Assert.False (dlg.Canceled);
  303. AssertIsTheSubfolder (dlg.Path);
  304. dlg.Dispose ();
  305. }
  306. [Theory]
  307. [InlineData (".csv", null, false)]
  308. [InlineData (".csv", "", false)]
  309. [InlineData (".csv", "c:\\MyFile.csv", true)]
  310. [InlineData (".csv", "c:\\MyFile.CSV", true)]
  311. [InlineData (".csv", "c:\\MyFile.csv.bak", false)]
  312. public void TestAllowedType_Basic (string allowed, string candidate, bool expected)
  313. {
  314. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  315. }
  316. [Theory]
  317. [InlineData (".Designer.cs", "c:\\MyView.Designer.cs", true)]
  318. [InlineData (".Designer.cs", "c:\\temp/MyView.Designer.cs", true)]
  319. [InlineData (".Designer.cs", "MyView.Designer.cs", true)]
  320. [InlineData (".Designer.cs", "c:\\MyView.DESIGNER.CS", true)]
  321. [InlineData (".Designer.cs", "MyView.cs", false)]
  322. public void TestAllowedType_DoubleBarreled (string allowed, string candidate, bool expected)
  323. {
  324. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  325. }
  326. [Theory]
  327. [InlineData ("Dockerfile", "c:\\temp\\Dockerfile", true)]
  328. [InlineData ("Dockerfile", "Dockerfile", true)]
  329. [InlineData ("Dockerfile", "someimg.Dockerfile", true)]
  330. public void TestAllowedType_SpecificFile (string allowed, string candidate, bool expected)
  331. {
  332. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  333. }
  334. [Fact]
  335. [AutoInitShutdown]
  336. public void TestDirectoryContents_Linux ()
  337. {
  338. if (IsWindows ())
  339. {
  340. return;
  341. }
  342. FileDialog fd = GetLinuxDialog ();
  343. fd.Title = string.Empty;
  344. fd.Style.Culture = new ("en-US");
  345. fd.Draw ();
  346. var expected =
  347. @$"
  348. ┌─────────────────────────────────────────────────────────────────────────┐
  349. │/demo/ │
  350. │{
  351. CM.Glyphs.LeftBracket
  352. }▲{
  353. CM.Glyphs.RightBracket
  354. } │
  355. │┌────────────┬──────────┬──────────────────────────────┬────────────────┐│
  356. ││Filename (▲)│Size │Modified │Type ││
  357. │├────────────┼──────────┼──────────────────────────────┼────────────────┤│
  358. ││.. │ │ │<Directory> ││
  359. ││/subfolder │ │2002-01-01T22:42:10 │<Directory> ││
  360. ││image.gif │4.00 B │2002-01-01T22:42:10 │.gif ││
  361. ││jQuery.js │7.00 B │2001-01-01T11:44:42 │.js ││
  362. │ │
  363. │ │
  364. │ │
  365. │{
  366. CM.Glyphs.LeftBracket
  367. } ►► {
  368. CM.Glyphs.RightBracket
  369. } Enter Search {
  370. CM.Glyphs.LeftBracket
  371. }{
  372. CM.Glyphs.LeftDefaultIndicator
  373. } OK {
  374. CM.Glyphs.RightDefaultIndicator
  375. }{
  376. CM.Glyphs.RightBracket
  377. } {
  378. CM.Glyphs.LeftBracket
  379. } Cancel {
  380. CM.Glyphs.RightBracket
  381. } │
  382. └─────────────────────────────────────────────────────────────────────────┘
  383. ";
  384. TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
  385. fd.Dispose ();
  386. }
  387. [Fact]
  388. [AutoInitShutdown]
  389. public void TestDirectoryContents_Windows ()
  390. {
  391. if (!IsWindows ())
  392. {
  393. return;
  394. }
  395. FileDialog fd = GetWindowsDialog ();
  396. fd.Title = string.Empty;
  397. fd.Style.Culture = new ("en-US");
  398. fd.Draw ();
  399. var expected =
  400. @$"
  401. ┌─────────────────────────────────────────────────────────────────────────┐
  402. │c:\demo\ │
  403. │{
  404. CM.Glyphs.LeftBracket
  405. }▲{
  406. CM.Glyphs.RightBracket
  407. } │
  408. │┌────────────┬──────────┬──────────────────────────────┬────────────────┐│
  409. ││Filename (▲)│Size │Modified │Type ││
  410. │├────────────┼──────────┼──────────────────────────────┼────────────────┤│
  411. ││.. │ │ │<Directory> ││
  412. ││\subfolder │ │2002-01-01T22:42:10 │<Directory> ││
  413. ││image.gif │4.00 B │2002-01-01T22:42:10 │.gif ││
  414. ││jQuery.js │7.00 B │2001-01-01T11:44:42 │.js ││
  415. ││mybinary.exe│7.00 B │2001-01-01T11:44:42 │.exe ││
  416. │ │
  417. │ │
  418. │{
  419. CM.Glyphs.LeftBracket
  420. } ►► {
  421. CM.Glyphs.RightBracket
  422. } Enter Search {
  423. CM.Glyphs.LeftBracket
  424. }{
  425. CM.Glyphs.LeftDefaultIndicator
  426. } OK {
  427. CM.Glyphs.RightDefaultIndicator
  428. }{
  429. CM.Glyphs.RightBracket
  430. } {
  431. CM.Glyphs.LeftBracket
  432. } Cancel {
  433. CM.Glyphs.RightBracket
  434. } │
  435. └─────────────────────────────────────────────────────────────────────────┘
  436. ";
  437. TestHelpers.AssertDriverContentsAre (expected, output, ignoreLeadingWhitespace: true);
  438. fd.Dispose ();
  439. }
  440. private void AssertIsTheRootDirectory (string path)
  441. {
  442. if (IsWindows ())
  443. {
  444. Assert.Equal (@"c:\", path);
  445. }
  446. else
  447. {
  448. Assert.Equal ("/", path);
  449. }
  450. }
  451. private void AssertIsTheStartingDirectory (string path)
  452. {
  453. if (IsWindows ())
  454. {
  455. Assert.Equal (@"c:\demo\", path);
  456. }
  457. else
  458. {
  459. Assert.Equal ("/demo/", path);
  460. }
  461. }
  462. private void AssertIsTheSubfolder (string path)
  463. {
  464. if (IsWindows ())
  465. {
  466. Assert.Equal (@"c:\demo\subfolder", path);
  467. }
  468. else
  469. {
  470. Assert.Equal ("/demo/subfolder", path);
  471. }
  472. }
  473. private void Begin (FileDialog dlg)
  474. {
  475. dlg.BeginInit ();
  476. dlg.EndInit ();
  477. Application.Begin (dlg);
  478. }
  479. private FileDialog GetDialog () { return IsWindows () ? GetWindowsDialog () : GetLinuxDialog (); }
  480. private FileDialog GetInitializedFileDialog ()
  481. {
  482. var dlg = new FileDialog ();
  483. Begin (dlg);
  484. return dlg;
  485. }
  486. private FileDialog GetLinuxDialog ()
  487. {
  488. // Arrange
  489. var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), "/");
  490. fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));
  491. fileSystem.AddFile (
  492. @"/myfile.txt",
  493. new ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
  494. );
  495. fileSystem.AddFile (
  496. @"/demo/jQuery.js",
  497. new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
  498. );
  499. fileSystem.AddFile (
  500. @"/demo/image.gif",
  501. new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
  502. {
  503. LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
  504. }
  505. );
  506. var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"/demo/subfolder");
  507. m.Create ();
  508. m.LastWriteTime = new (2002, 01, 01, 22, 42, 10);
  509. fileSystem.AddFile (
  510. @"/demo/subfolder/image2.gif",
  511. new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
  512. {
  513. LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
  514. }
  515. );
  516. var fd = new FileDialog (fileSystem) { Height = 15, Width = 75 };
  517. fd.Path = @"/demo/";
  518. Begin (fd);
  519. return fd;
  520. }
  521. private FileDialog GetWindowsDialog ()
  522. {
  523. // Arrange
  524. var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), @"c:\");
  525. fileSystem.MockTime (() => new (2010, 01, 01, 11, 12, 43));
  526. fileSystem.AddFile (
  527. @"c:\myfile.txt",
  528. new ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) }
  529. );
  530. fileSystem.AddFile (
  531. @"c:\demo\jQuery.js",
  532. new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
  533. );
  534. fileSystem.AddFile (
  535. @"c:\demo\mybinary.exe",
  536. new ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) }
  537. );
  538. fileSystem.AddFile (
  539. @"c:\demo\image.gif",
  540. new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
  541. {
  542. LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
  543. }
  544. );
  545. var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"c:\demo\subfolder");
  546. m.Create ();
  547. m.LastWriteTime = new (2002, 01, 01, 22, 42, 10);
  548. fileSystem.AddFile (
  549. @"c:\demo\subfolder\image2.gif",
  550. new (new byte [] { 0x12, 0x34, 0x56, 0xd2 })
  551. {
  552. LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10)
  553. }
  554. );
  555. var fd = new FileDialog (fileSystem) { Height = 15, Width = 75 };
  556. fd.Path = @"c:\demo\";
  557. Begin (fd);
  558. return fd;
  559. }
  560. /*
  561. [Fact, AutoInitShutdown]
  562. public void Autocomplete_NoSuggestion_WhenTextMatchesExactly ()
  563. {
  564. var tb = new TextFieldWithAppendAutocomplete ();
  565. ForceFocus (tb);
  566. tb.Text = "/bob/fish";
  567. tb.CursorPosition = tb.Text.Length;
  568. tb.GenerateSuggestions (null, "fish", "fishes");
  569. // should not report success for autocompletion because we already have that exact
  570. // string
  571. Assert.False (tb.AcceptSelectionIfAny ());
  572. }
  573. [Fact, AutoInitShutdown]
  574. public void Autocomplete_AcceptSuggstion ()
  575. {
  576. var tb = new TextFieldWithAppendAutocomplete ();
  577. ForceFocus (tb);
  578. tb.Text = @"/bob/fi";
  579. tb.CursorPosition = tb.Text.Length;
  580. tb.GenerateSuggestions (null, "fish", "fishes");
  581. Assert.True (tb.AcceptSelectionIfAny ());
  582. Assert.Equal (@"/bob/fish", tb.Text);
  583. }*/
  584. private bool IsWindows () { return RuntimeInformation.IsOSPlatform (OSPlatform.Windows); }
  585. private void Send (char ch, ConsoleKey ck, bool shift = false, bool alt = false, bool control = false)
  586. {
  587. Application.Driver.SendKeys (ch, ck, shift, alt, control);
  588. }
  589. private void Send (string chars)
  590. {
  591. foreach (char ch in chars)
  592. {
  593. Application.Driver.SendKeys (ch, ConsoleKey.NoName, false, false, false);
  594. }
  595. }
  596. private void SendSlash ()
  597. {
  598. if (Path.DirectorySeparatorChar == '/')
  599. {
  600. Send ('/', ConsoleKey.Separator);
  601. }
  602. else
  603. {
  604. Send ('\\', ConsoleKey.Separator);
  605. }
  606. }
  607. }