FileDialogTests.cs 21 KB

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