FileDialogTests.cs 20 KB

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