FileDialogTests.cs 24 KB

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