FileDialogTests.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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.Single (dlg.MultiSelected);
  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.Single (eventMultiSelected);
  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.Single (dlg.MultiSelected);
  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.Single (eventMultiSelected);
  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. [Theory]
  364. [InlineData (".csv", null, false)]
  365. [InlineData (".csv", "", false)]
  366. [InlineData (".csv", "c:\\MyFile.csv", true)]
  367. [InlineData (".csv", "c:\\MyFile.CSV", true)]
  368. [InlineData (".csv", "c:\\MyFile.csv.bak", false)]
  369. public void TestAllowedType_Basic (string allowed, string candidate, bool expected)
  370. {
  371. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  372. }
  373. [Theory]
  374. [InlineData ("Dockerfile", "c:\\temp\\Dockerfile", true)]
  375. [InlineData ("Dockerfile", "Dockerfile", true)]
  376. [InlineData ("Dockerfile", "someimg.Dockerfile", true)]
  377. public void TestAllowedType_SpecificFile (string allowed, string candidate, bool expected)
  378. {
  379. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  380. }
  381. [Theory]
  382. [InlineData (".Designer.cs", "c:\\MyView.Designer.cs", true)]
  383. [InlineData (".Designer.cs", "c:\\temp/MyView.Designer.cs", true)]
  384. [InlineData (".Designer.cs", "MyView.Designer.cs", true)]
  385. [InlineData (".Designer.cs", "c:\\MyView.DESIGNER.CS", true)]
  386. [InlineData (".Designer.cs", "MyView.cs", false)]
  387. public void TestAllowedType_DoubleBarreled (string allowed, string candidate, bool expected)
  388. {
  389. Assert.Equal (expected, new AllowedType ("Test", allowed).IsAllowed (candidate));
  390. }
  391. [Theory, AutoInitShutdown]
  392. [InlineData (true)]
  393. [InlineData (false)]
  394. public void CancelSelection (bool cancel)
  395. {
  396. var dlg = GetInitializedFileDialog ();
  397. var openIn = Path.Combine (Environment.CurrentDirectory, "zz");
  398. Directory.CreateDirectory (openIn);
  399. dlg.Path = openIn + Path.DirectorySeparatorChar;
  400. dlg.FilesSelected += (s, e) => e.Cancel = cancel;
  401. //pressing enter will complete the current selection
  402. // unless the event cancels the confirm
  403. Send ('\n', ConsoleKey.Enter, false);
  404. Assert.Equal (cancel, dlg.Canceled);
  405. }
  406. private void Send (char ch, ConsoleKey ck, bool shift = false, bool alt = false, bool control = false)
  407. {
  408. Application.Driver.SendKeys (ch, ck, shift, alt, control);
  409. }
  410. private void Send (string chars)
  411. {
  412. foreach (var ch in chars) {
  413. Application.Driver.SendKeys (ch, ConsoleKey.NoName, false, false, false);
  414. }
  415. }
  416. /*
  417. [Fact, AutoInitShutdown]
  418. public void Autocomplete_NoSuggestion_WhenTextMatchesExactly ()
  419. {
  420. var tb = new TextFieldWithAppendAutocomplete ();
  421. ForceFocus (tb);
  422. tb.Text = "/bob/fish";
  423. tb.CursorPosition = tb.Text.Length;
  424. tb.GenerateSuggestions (null, "fish", "fishes");
  425. // should not report success for autocompletion because we already have that exact
  426. // string
  427. Assert.False (tb.AcceptSelectionIfAny ());
  428. }
  429. [Fact, AutoInitShutdown]
  430. public void Autocomplete_AcceptSuggstion ()
  431. {
  432. var tb = new TextFieldWithAppendAutocomplete ();
  433. ForceFocus (tb);
  434. tb.Text = @"/bob/fi";
  435. tb.CursorPosition = tb.Text.Length;
  436. tb.GenerateSuggestions (null, "fish", "fishes");
  437. Assert.True (tb.AcceptSelectionIfAny ());
  438. Assert.Equal (@"/bob/fish", tb.Text);
  439. }*/
  440. private bool IsWindows ()
  441. {
  442. return System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform (System.Runtime.InteropServices.OSPlatform.Windows);
  443. }
  444. private FileDialog GetDialog ()
  445. {
  446. return IsWindows () ? GetWindowsDialog () : GetLinuxDialog ();
  447. }
  448. private FileDialog GetWindowsDialog ()
  449. {
  450. // Arrange
  451. var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), @"c:\");
  452. fileSystem.MockTime (() => new DateTime (2010, 01, 01, 11, 12, 43));
  453. fileSystem.AddFile (@"c:\myfile.txt", new MockFileData ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) });
  454. fileSystem.AddFile (@"c:\demo\jQuery.js", new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) });
  455. fileSystem.AddFile (@"c:\demo\mybinary.exe", new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) });
  456. fileSystem.AddFile (@"c:\demo\image.gif", new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 }) { LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10) });
  457. var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"c:\demo\subfolder");
  458. m.Create ();
  459. m.LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10);
  460. fileSystem.AddFile (@"c:\demo\subfolder\image2.gif", new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 }) { LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10) });
  461. var fd = new FileDialog (fileSystem) {
  462. Height = 15
  463. };
  464. fd.Path = @"c:\demo\";
  465. Begin (fd);
  466. return fd;
  467. }
  468. private FileDialog GetLinuxDialog ()
  469. {
  470. // Arrange
  471. var fileSystem = new MockFileSystem (new Dictionary<string, MockFileData> (), "/");
  472. fileSystem.MockTime (() => new DateTime (2010, 01, 01, 11, 12, 43));
  473. fileSystem.AddFile (@"/myfile.txt", new MockFileData ("Testing is meh.") { LastWriteTime = new DateTime (2001, 01, 01, 11, 12, 11) });
  474. fileSystem.AddFile (@"/demo/jQuery.js", new MockFileData ("some js") { LastWriteTime = new DateTime (2001, 01, 01, 11, 44, 42) });
  475. fileSystem.AddFile (@"/demo/image.gif", new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 }) { LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10) });
  476. var m = (MockDirectoryInfo)fileSystem.DirectoryInfo.New (@"/demo/subfolder");
  477. m.Create ();
  478. m.LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10);
  479. fileSystem.AddFile (@"/demo/subfolder/image2.gif", new MockFileData (new byte [] { 0x12, 0x34, 0x56, 0xd2 }) { LastWriteTime = new DateTime (2002, 01, 01, 22, 42, 10) });
  480. var fd = new FileDialog (fileSystem) {
  481. Height = 15
  482. };
  483. fd.Path = @"/demo/";
  484. Begin (fd);
  485. return fd;
  486. }
  487. private FileDialog GetInitializedFileDialog ()
  488. {
  489. var dlg = new FileDialog ();
  490. Begin (dlg);
  491. return dlg;
  492. }
  493. private void Begin (FileDialog dlg)
  494. {
  495. dlg.BeginInit ();
  496. dlg.EndInit ();
  497. Application.Begin (dlg);
  498. }
  499. }
  500. }