FileDialogTests.cs 25 KB

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