FileTest.cs 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240
  1. //
  2. // FileTest.cs: Test cases for System.IO.File
  3. //
  4. // Author:
  5. // Duncan Mak ([email protected])
  6. // Ville Palo ([email protected])
  7. //
  8. // (C) 2002 Ximian, Inc. http://www.ximian.com
  9. //
  10. using NUnit.Framework;
  11. using System;
  12. using System.IO;
  13. using System.Globalization;
  14. using System.Threading;
  15. namespace MonoTests.System.IO
  16. {
  17. [TestFixture]
  18. public class FileTest : Assertion
  19. {
  20. static string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
  21. [SetUp]
  22. public void SetUp ()
  23. {
  24. if (Directory.Exists (TempFolder))
  25. Directory.Delete (TempFolder, true);
  26. Directory.CreateDirectory (TempFolder);
  27. Thread.CurrentThread.CurrentCulture = new CultureInfo ("EN-us");
  28. }
  29. [TearDown]
  30. public void TearDown ()
  31. {
  32. if (Directory.Exists (TempFolder))
  33. Directory.Delete (TempFolder, true);
  34. }
  35. [Test]
  36. public void TestExists ()
  37. {
  38. int i = 0;
  39. try {
  40. Assert ("null filename should not exist", !File.Exists (null));
  41. i++;
  42. Assert ("empty filename should not exist", !File.Exists (""));
  43. i++;
  44. Assert ("whitespace filename should not exist", !File.Exists (" \t\t \t \n\t\n \n"));
  45. i++;
  46. string path = TempFolder + Path.DirectorySeparatorChar + "AFile.txt";
  47. DeleteFile (path);
  48. File.Create (path).Close ();
  49. Assert ("File " + path + " should exists", File.Exists (path));
  50. i++;
  51. Assert ("File resources" + Path.DirectorySeparatorChar + "doesnotexist should not exist", !File.Exists (TempFolder + Path.DirectorySeparatorChar + "doesnotexist"));
  52. } catch (Exception e) {
  53. Fail ("Unexpected exception at i = " + i + ". e=" + e);
  54. }
  55. }
  56. [Test]
  57. public void TestCreate ()
  58. {
  59. FileStream stream;
  60. /* exception test: File.Create(null) */
  61. try {
  62. stream = File.Create (null);
  63. Fail ("File.Create(null) should throw ArgumentNullException");
  64. } catch (ArgumentNullException) {
  65. // do nothing, this is what we expect
  66. } catch (Exception e) {
  67. Fail ("File.Create(null) unexpected exception caught: e=" + e.ToString());
  68. }
  69. /* exception test: File.Create("") */
  70. try {
  71. stream = File.Create ("");
  72. Fail ("File.Create('') should throw ArgumentException");
  73. } catch (ArgumentException) {
  74. // do nothing, this is what we expect
  75. } catch (Exception e) {
  76. Fail ("File.Create('') unexpected exception caught: e=" + e.ToString());
  77. }
  78. /* exception test: File.Create(" ") */
  79. try {
  80. stream = File.Create (" ");
  81. Fail ("File.Create(' ') should throw ArgumentException");
  82. } catch (ArgumentException) {
  83. // do nothing, this is what we expect
  84. } catch (Exception e) {
  85. Fail ("File.Create(' ') unexpected exception caught: e=" + e.ToString());
  86. }
  87. /* exception test: File.Create(directory_not_found) */
  88. try {
  89. stream = File.Create (TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo");
  90. Fail ("File.Create(directory_does_not_exist) should throw DirectoryNotFoundException");
  91. } catch (DirectoryNotFoundException) {
  92. // do nothing, this is what we expect
  93. } catch (Exception e) {
  94. Fail ("File.Create(directory_does_not_exist) unexpected exception caught: e=" + e.ToString());
  95. }
  96. /* positive test: create resources/foo */
  97. try {
  98. stream = File.Create (TempFolder + Path.DirectorySeparatorChar + "foo");
  99. Assert ("File should exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "foo"));
  100. stream.Close ();
  101. } catch (Exception e) {
  102. Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
  103. }
  104. /* positive test: repeat test above again to test for overwriting file */
  105. try {
  106. stream = File.Create (TempFolder + Path.DirectorySeparatorChar + "foo");
  107. Assert ("File should exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "foo"));
  108. stream.Close ();
  109. } catch (Exception e) {
  110. Fail ("File.Create(resources/foo) unexpected exception caught: e=" + e.ToString());
  111. }
  112. }
  113. [Test]
  114. public void TestCopy ()
  115. {
  116. /* exception test: File.Copy(null, b) */
  117. try {
  118. File.Copy (null, "b");
  119. Fail ("File.Copy(null, 'b') should throw ArgumentNullException");
  120. } catch (ArgumentNullException) {
  121. // do nothing, this is what we expect
  122. } catch (Exception e) {
  123. Fail ("File.Copy(null, 'b') unexpected exception caught: e=" + e.ToString());
  124. }
  125. /* exception test: File.Copy(a, null) */
  126. try {
  127. File.Copy ("a", null);
  128. Fail ("File.Copy('a', null) should throw ArgumentNullException");
  129. } catch (ArgumentNullException) {
  130. // do nothing, this is what we expect
  131. } catch (Exception e) {
  132. Fail ("File.Copy('a', null) unexpected exception caught: e=" + e.ToString());
  133. }
  134. /* exception test: File.Copy("", b) */
  135. try {
  136. File.Copy ("", "b");
  137. Fail ("File.Copy('', 'b') should throw ArgumentException");
  138. } catch (ArgumentException) {
  139. // do nothing, this is what we expect
  140. } catch (Exception e) {
  141. Fail ("File.Copy('', 'b') unexpected exception caught: e=" + e.ToString());
  142. }
  143. /* exception test: File.Copy(a, "") */
  144. try {
  145. File.Copy ("a", "");
  146. Fail ("File.Copy('a', '') should throw ArgumentException");
  147. } catch (ArgumentException) {
  148. // do nothing, this is what we expect
  149. } catch (Exception e) {
  150. Fail ("File.Copy('a', '') unexpected exception caught: e=" + e.ToString());
  151. }
  152. /* exception test: File.Copy(" ", b) */
  153. try {
  154. File.Copy (" ", "b");
  155. Fail ("File.Copy(' ', 'b') should throw ArgumentException");
  156. } catch (ArgumentException) {
  157. // do nothing, this is what we expect
  158. } catch (Exception e) {
  159. Fail ("File.Copy(' ', 'b') unexpected exception caught: e=" + e.ToString());
  160. }
  161. /* exception test: File.Copy(a, " ") */
  162. try {
  163. File.Copy ("a", " ");
  164. Fail ("File.Copy('a', ' ') should throw ArgumentException");
  165. } catch (ArgumentException) {
  166. // do nothing, this is what we expect
  167. } catch (Exception e) {
  168. Fail ("File.Copy('a', ' ') unexpected exception caught: e=" + e.ToString());
  169. }
  170. /* exception test: File.Copy(doesnotexist, b) */
  171. try {
  172. File.Copy ("doesnotexist", "b");
  173. Fail ("File.Copy('doesnotexist', 'b') should throw FileNotFoundException");
  174. } catch (FileNotFoundException) {
  175. // do nothing, this is what we expect
  176. } catch (Exception e) {
  177. Fail ("File.Copy('doesnotexist', 'b') unexpected exception caught: e=" + e.ToString());
  178. }
  179. /* positive test: copy resources/AFile.txt to resources/bar */
  180. try {
  181. DeleteFile (TempFolder + Path.DirectorySeparatorChar + "bar");
  182. DeleteFile (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  183. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
  184. File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
  185. Assert ("File AFile.txt should still exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"));
  186. Assert ("File bar should exist after File.Copy", File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar"));
  187. } catch (Exception e) {
  188. Fail ("#1 File.Copy('resources/AFile.txt', 'resources/bar') unexpected exception caught: e=" + e.ToString());
  189. }
  190. /* exception test: File.Copy(resources/AFile.txt, resources/bar) (default is overwrite == false) */
  191. try {
  192. File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar");
  193. Fail ("File.Copy('resources/AFile.txt', 'resources/bar') should throw IOException");
  194. } catch (IOException) {
  195. // do nothing, this is what we expect
  196. } catch (Exception e) {
  197. Fail ("#2 File.Copy('resources/AFile.txt', 'resources/bar') unexpected exception caught: e=" + e.ToString());
  198. }
  199. /* positive test: copy resources/AFile.txt to resources/bar, overwrite */
  200. try {
  201. Assert ("File bar should exist before File.Copy", File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar"));
  202. File.Copy (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", TempFolder + Path.DirectorySeparatorChar + "bar", true);
  203. Assert ("File AFile.txt should still exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"));
  204. Assert ("File bar should exist after File.Copy", File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar"));
  205. } catch (Exception e) {
  206. Fail ("File.Copy('resources/AFile.txt', 'resources/bar', true) unexpected exception caught: e=" + e.ToString());
  207. }
  208. }
  209. [Test]
  210. [ExpectedException (typeof (ArgumentNullException))]
  211. public void DeleteArgumentNullException ()
  212. {
  213. File.Delete (null);
  214. }
  215. [Test]
  216. [ExpectedException (typeof (ArgumentException))]
  217. public void DeleteArgumentException1 ()
  218. {
  219. File.Delete ("");
  220. }
  221. [Test]
  222. [ExpectedException (typeof (ArgumentException))]
  223. public void DeleteArgumentException2 ()
  224. {
  225. File.Delete (" ");
  226. }
  227. [Test]
  228. [ExpectedException (typeof (DirectoryNotFoundException))]
  229. public void DeleteDirectoryNotFoundException ()
  230. {
  231. string path = TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist" + Path.DirectorySeparatorChar + "foo";
  232. if (Directory.Exists (TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist"))
  233. Directory.Delete (TempFolder + Path.DirectorySeparatorChar + "directory_does_not_exist", true);
  234. File.Delete (path);
  235. DeleteFile (path);
  236. }
  237. [Test]
  238. public void TestDelete ()
  239. {
  240. string foopath = TempFolder + Path.DirectorySeparatorChar + "foo";
  241. DeleteFile (foopath);
  242. File.Create (foopath).Close ();
  243. try {
  244. File.Delete (foopath);
  245. } catch (Exception e) {
  246. Fail ("Unable to delete " + foopath + " e=" + e.ToString());
  247. }
  248. Assert ("File " + foopath + " should not exist after File.Delete", !File.Exists (foopath));
  249. DeleteFile (foopath);
  250. }
  251. [Test]
  252. [ExpectedException(typeof (IOException))]
  253. public void DeleteOpenStreamException ()
  254. {
  255. string path = TempFolder + Path.DirectorySeparatorChar + "DeleteOpenStreamException";
  256. DeleteFile (path);
  257. FileStream stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.ReadWrite);
  258. File.Delete (path);
  259. }
  260. [Test]
  261. [ExpectedException(typeof (ArgumentNullException))]
  262. public void MoveException1 ()
  263. {
  264. File.Move (null, "b");
  265. }
  266. [Test]
  267. [ExpectedException(typeof (ArgumentNullException))]
  268. public void MoveException2 ()
  269. {
  270. File.Move ("a", null);
  271. }
  272. [Test]
  273. [ExpectedException(typeof (ArgumentException))]
  274. public void MoveException3 ()
  275. {
  276. File.Move ("", "b");
  277. }
  278. [Test]
  279. [ExpectedException(typeof (ArgumentException))]
  280. public void MoveException4 ()
  281. {
  282. File.Move ("a", "");
  283. }
  284. [Test]
  285. [ExpectedException(typeof (ArgumentException))]
  286. public void MoveException5 ()
  287. {
  288. File.Move (" ", "b");
  289. }
  290. [Test]
  291. [ExpectedException(typeof (ArgumentException))]
  292. public void MoveException6 ()
  293. {
  294. File.Move ("a", " ");
  295. }
  296. [Test]
  297. [ExpectedException(typeof (FileNotFoundException))]
  298. public void MoveException7 ()
  299. {
  300. DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist");
  301. File.Move (TempFolder + Path.DirectorySeparatorChar + "doesnotexist", "b");
  302. }
  303. [Test]
  304. [ExpectedException(typeof (DirectoryNotFoundException))]
  305. public void MoveException8 ()
  306. {
  307. string path = TempFolder + Path.DirectorySeparatorChar + "foo";
  308. DeleteFile (path);
  309. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
  310. File.Copy(TempFolder + Path.DirectorySeparatorChar + "AFile.txt", path, true);
  311. DeleteFile (TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
  312. File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder + Path.DirectorySeparatorChar + "doesnotexist" + Path.DirectorySeparatorChar + "b");
  313. }
  314. [Test]
  315. [ExpectedException(typeof (IOException))]
  316. public void MoveException9 ()
  317. {
  318. File.Move (TempFolder + Path.DirectorySeparatorChar + "foo", TempFolder);
  319. }
  320. [Test]
  321. public void TestMove ()
  322. {
  323. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar")) {
  324. FileStream f = File.Create(TempFolder + Path.DirectorySeparatorChar + "bar");
  325. f.Close();
  326. }
  327. Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar"));
  328. File.Move (TempFolder + Path.DirectorySeparatorChar + "bar", TempFolder + Path.DirectorySeparatorChar + "baz");
  329. Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "bar should not exist", !File.Exists (TempFolder + Path.DirectorySeparatorChar + "bar"));
  330. Assert ("File " + TempFolder + Path.DirectorySeparatorChar + "baz should exist", File.Exists (TempFolder + Path.DirectorySeparatorChar + "baz"));
  331. // Test moving of directories
  332. string dir = Path.Combine (TempFolder, "dir");
  333. string dir2 = Path.Combine (TempFolder, "dir2");
  334. string dir_foo = Path.Combine (dir, "foo");
  335. string dir2_foo = Path.Combine (dir2, "foo");
  336. Directory.CreateDirectory (dir);
  337. File.Create (dir_foo);
  338. File.Move (dir, dir2);
  339. Assert (!Directory.Exists (dir));
  340. Assert (Directory.Exists (dir2));
  341. Assert (File.Exists (dir2_foo));
  342. }
  343. [Test]
  344. public void TestOpen ()
  345. {
  346. try {
  347. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"))
  348. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  349. FileStream stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.Open);
  350. stream.Close ();
  351. } catch (Exception e) {
  352. Fail ("Unable to open " + TempFolder + Path.DirectorySeparatorChar + "AFile.txt: e=" + e.ToString());
  353. }
  354. /* Exception tests */
  355. try {
  356. FileStream stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist", FileMode.Open);
  357. Fail ("File 'filedoesnotexist' should not exist");
  358. } catch (FileNotFoundException) {
  359. // do nothing, this is what we expect
  360. } catch (Exception e) {
  361. Fail ("Unexpect exception caught: e=" + e.ToString());
  362. }
  363. }
  364. [Test]
  365. public void Open ()
  366. {
  367. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"))
  368. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt").Close ();
  369. FileStream stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.Open);
  370. Assertion.AssertEquals ("test#01", true, stream.CanRead);
  371. Assertion.AssertEquals ("test#02", true, stream.CanSeek);
  372. Assertion.AssertEquals ("test#03", true, stream.CanWrite);
  373. stream.Close ();
  374. stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.Open, FileAccess.Write);
  375. Assertion.AssertEquals ("test#04", false, stream.CanRead);
  376. Assertion.AssertEquals ("test#05", true, stream.CanSeek);
  377. Assertion.AssertEquals ("test#06", true, stream.CanWrite);
  378. stream.Close ();
  379. stream = File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.Open, FileAccess.Read);
  380. Assertion.AssertEquals ("test#04", true, stream.CanRead);
  381. Assertion.AssertEquals ("test#05", true, stream.CanSeek);
  382. Assertion.AssertEquals ("test#06", false, stream.CanWrite);
  383. stream.Close ();
  384. }
  385. [Test]
  386. [ExpectedException(typeof(ArgumentException))]
  387. public void OpenException1 ()
  388. {
  389. // CreateNew + Read throws an exceptoin
  390. File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.CreateNew, FileAccess.Read);
  391. }
  392. [Test]
  393. [ExpectedException(typeof(ArgumentException))]
  394. public void OpenException2 ()
  395. {
  396. // Append + Read throws an exceptoin
  397. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"))
  398. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  399. File.Open (TempFolder + Path.DirectorySeparatorChar + "AFile.txt", FileMode.Append, FileAccess.Read);
  400. }
  401. [Test]
  402. public void OpenRead ()
  403. {
  404. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"))
  405. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  406. FileStream stream = File.OpenRead (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  407. Assertion.AssertEquals ("test#01", true, stream.CanRead);
  408. Assertion.AssertEquals ("test#02", true, stream.CanSeek);
  409. Assertion.AssertEquals ("test#03", false, stream.CanWrite);
  410. stream.Close ();
  411. }
  412. [Test]
  413. public void OpenWrite ()
  414. {
  415. if (!File.Exists (TempFolder + Path.DirectorySeparatorChar + "AFile.txt"))
  416. File.Create (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  417. FileStream stream = File.OpenWrite (TempFolder + Path.DirectorySeparatorChar + "AFile.txt");
  418. Assertion.AssertEquals ("test#01", false, stream.CanRead);
  419. Assertion.AssertEquals ("test#02", true, stream.CanSeek);
  420. Assertion.AssertEquals ("test#03", true, stream.CanWrite);
  421. stream.Close ();
  422. }
  423. [Test]
  424. public void TestGetCreationTime ()
  425. {
  426. string path = TempFolder + Path.DirectorySeparatorChar + "baz";
  427. DeleteFile (path);
  428. File.Create (path).Close();
  429. DateTime time = File.GetCreationTime (path);
  430. time = time.ToLocalTime ();
  431. Assert ("GetCreationTime incorrect", (DateTime.Now - time).TotalSeconds < 10);
  432. DeleteFile (path);
  433. }
  434. [Test]
  435. [ExpectedException(typeof(IOException))]
  436. public void TestGetCreationTimeException ()
  437. {
  438. // Test nonexistent files
  439. string path2 = TempFolder + Path.DirectorySeparatorChar + "filedoesnotexist";
  440. DeleteFile (path2);
  441. // should throw an exception
  442. File.GetCreationTime (path2);
  443. }
  444. [Test]
  445. public void CreationTime ()
  446. {
  447. string path = TempFolder + Path.DirectorySeparatorChar + "creationTime";
  448. if (File.Exists (path))
  449. File.Delete (path);
  450. FileStream stream = File.Create (path);
  451. stream.Close ();
  452. File.SetCreationTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
  453. DateTime time = File.GetCreationTime (path);
  454. Assertion.AssertEquals ("test#01", 2002, time.Year);
  455. Assertion.AssertEquals ("test#02", 4, time.Month);
  456. Assertion.AssertEquals ("test#03", 6, time.Day);
  457. Assertion.AssertEquals ("test#04", 4, time.Hour);
  458. Assertion.AssertEquals ("test#05", 4, time.Second);
  459. time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetCreationTimeUtc (path));
  460. Assertion.AssertEquals ("test#06", 2002, time.Year);
  461. Assertion.AssertEquals ("test#07", 4, time.Month);
  462. Assertion.AssertEquals ("test#08", 6, time.Day);
  463. Assertion.AssertEquals ("test#09", 4, time.Hour);
  464. Assertion.AssertEquals ("test#10", 4, time.Second);
  465. File.SetCreationTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
  466. time = File.GetCreationTimeUtc (path);
  467. Assertion.AssertEquals ("test#11", 2002, time.Year);
  468. Assertion.AssertEquals ("test#12", 4, time.Month);
  469. Assertion.AssertEquals ("test#13", 6, time.Day);
  470. Assertion.AssertEquals ("test#14", 4, time.Hour);
  471. Assertion.AssertEquals ("test#15", 4, time.Second);
  472. time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetCreationTime (path));
  473. Assertion.AssertEquals ("test#16", 2002, time.Year);
  474. Assertion.AssertEquals ("test#17", 4, time.Month);
  475. Assertion.AssertEquals ("test#18", 6, time.Day);
  476. Assertion.AssertEquals ("test#19", 4, time.Hour);
  477. Assertion.AssertEquals ("test#20", 4, time.Second);
  478. }
  479. [Test]
  480. public void LastAccessTime ()
  481. {
  482. string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
  483. if (File.Exists (path))
  484. File.Delete (path);
  485. FileStream stream = File.Create (path);
  486. stream.Close ();
  487. File.SetLastAccessTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
  488. DateTime time = File.GetLastAccessTime (path);
  489. Assertion.AssertEquals ("test#01", 2002, time.Year);
  490. Assertion.AssertEquals ("test#02", 4, time.Month);
  491. Assertion.AssertEquals ("test#03", 6, time.Day);
  492. Assertion.AssertEquals ("test#04", 4, time.Hour);
  493. Assertion.AssertEquals ("test#05", 4, time.Second);
  494. time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastAccessTimeUtc (path));
  495. Assertion.AssertEquals ("test#06", 2002, time.Year);
  496. Assertion.AssertEquals ("test#07", 4, time.Month);
  497. Assertion.AssertEquals ("test#08", 6, time.Day);
  498. Assertion.AssertEquals ("test#09", 4, time.Hour);
  499. Assertion.AssertEquals ("test#10", 4, time.Second);
  500. File.SetLastAccessTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
  501. time = File.GetLastAccessTimeUtc (path);
  502. Assertion.AssertEquals ("test#11", 2002, time.Year);
  503. Assertion.AssertEquals ("test#12", 4, time.Month);
  504. Assertion.AssertEquals ("test#13", 6, time.Day);
  505. Assertion.AssertEquals ("test#14", 4, time.Hour);
  506. Assertion.AssertEquals ("test#15", 4, time.Second);
  507. time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastAccessTime (path));
  508. Assertion.AssertEquals ("test#16", 2002, time.Year);
  509. Assertion.AssertEquals ("test#17", 4, time.Month);
  510. Assertion.AssertEquals ("test#18", 6, time.Day);
  511. Assertion.AssertEquals ("test#19", 4, time.Hour);
  512. Assertion.AssertEquals ("test#20", 4, time.Second);
  513. }
  514. [Test]
  515. public void LastWriteTime ()
  516. {
  517. string path = TempFolder + Path.DirectorySeparatorChar + "lastWriteTime";
  518. if (File.Exists (path))
  519. File.Delete (path);
  520. FileStream stream = File.Create (path);
  521. stream.Close ();
  522. File.SetLastWriteTime (path, new DateTime (2002, 4, 6, 4, 6, 4));
  523. DateTime time = File.GetLastWriteTime (path);
  524. Assertion.AssertEquals ("test#01", 2002, time.Year);
  525. Assertion.AssertEquals ("test#02", 4, time.Month);
  526. Assertion.AssertEquals ("test#03", 6, time.Day);
  527. Assertion.AssertEquals ("test#04", 4, time.Hour);
  528. Assertion.AssertEquals ("test#05", 4, time.Second);
  529. time = TimeZone.CurrentTimeZone.ToLocalTime (File.GetLastWriteTimeUtc (path));
  530. Assertion.AssertEquals ("test#06", 2002, time.Year);
  531. Assertion.AssertEquals ("test#07", 4, time.Month);
  532. Assertion.AssertEquals ("test#08", 6, time.Day);
  533. Assertion.AssertEquals ("test#09", 4, time.Hour);
  534. Assertion.AssertEquals ("test#10", 4, time.Second);
  535. File.SetLastWriteTimeUtc (path, new DateTime (2002, 4, 6, 4, 6, 4));
  536. time = File.GetLastWriteTimeUtc (path);
  537. Assertion.AssertEquals ("test#11", 2002, time.Year);
  538. Assertion.AssertEquals ("test#12", 4, time.Month);
  539. Assertion.AssertEquals ("test#13", 6, time.Day);
  540. Assertion.AssertEquals ("test#14", 4, time.Hour);
  541. Assertion.AssertEquals ("test#15", 4, time.Second);
  542. time = TimeZone.CurrentTimeZone.ToUniversalTime (File.GetLastWriteTime (path));
  543. Assertion.AssertEquals ("test#16", 2002, time.Year);
  544. Assertion.AssertEquals ("test#17", 4, time.Month);
  545. Assertion.AssertEquals ("test#18", 6, time.Day);
  546. Assertion.AssertEquals ("test#19", 4, time.Hour);
  547. Assertion.AssertEquals ("test#20", 4, time.Second);
  548. }
  549. [Test]
  550. [ExpectedException(typeof(ArgumentNullException))]
  551. public void GetCreationTimeException1 ()
  552. {
  553. File.GetCreationTime (null as string);
  554. }
  555. [Test]
  556. [ExpectedException(typeof(ArgumentException))]
  557. public void GetCreationTimeException2 ()
  558. {
  559. File.GetCreationTime ("");
  560. }
  561. [Test]
  562. [ExpectedException(typeof(IOException))]
  563. public void GetCreationTimeException3 ()
  564. {
  565. string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
  566. DeleteFile (path);
  567. File.GetCreationTime (path);
  568. }
  569. [Test]
  570. [ExpectedException(typeof(ArgumentException))]
  571. public void GetCreationTimeException4 ()
  572. {
  573. File.GetCreationTime (" ");
  574. }
  575. [Test]
  576. [ExpectedException(typeof(ArgumentException))]
  577. public void GetCreationTimeException5 ()
  578. {
  579. File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
  580. }
  581. [Test]
  582. [ExpectedException(typeof(ArgumentNullException))]
  583. public void GetCreationTimeUtcException1 ()
  584. {
  585. File.GetCreationTimeUtc (null as string);
  586. }
  587. [Test]
  588. [ExpectedException(typeof(ArgumentException))]
  589. public void GetCreationTimeUtcException2 ()
  590. {
  591. File.GetCreationTimeUtc ("");
  592. }
  593. [Test]
  594. [ExpectedException(typeof(IOException))]
  595. public void GetCreationTimeUtcException3 ()
  596. {
  597. string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
  598. DeleteFile (path);
  599. File.GetCreationTimeUtc (path);
  600. }
  601. [Test]
  602. [ExpectedException(typeof(ArgumentException))]
  603. public void GetCreationTimeUtcException4 ()
  604. {
  605. File.GetCreationTimeUtc (" ");
  606. }
  607. [Test]
  608. [ExpectedException(typeof(ArgumentException))]
  609. public void GetCreationTimeUtcException5 ()
  610. {
  611. File.GetCreationTime (Path.InvalidPathChars [0].ToString ());
  612. }
  613. [Test]
  614. [ExpectedException(typeof(ArgumentNullException))]
  615. public void GetLastAccessTimeException1 ()
  616. {
  617. File.GetLastAccessTime (null as string);
  618. }
  619. [Test]
  620. [ExpectedException(typeof(ArgumentException))]
  621. public void GetLastAccessTimeException2 ()
  622. {
  623. File.GetLastAccessTime ("");
  624. }
  625. [Test]
  626. [ExpectedException(typeof(IOException))]
  627. public void GetLastAccessTimeException3 ()
  628. {
  629. string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
  630. DeleteFile (path);
  631. File.GetLastAccessTime (path);
  632. }
  633. [Test]
  634. [ExpectedException(typeof(ArgumentException))]
  635. public void GetLastAccessTimeException4 ()
  636. {
  637. File.GetLastAccessTime (" ");
  638. }
  639. [Test]
  640. [ExpectedException(typeof(ArgumentException))]
  641. public void GetLastAccessTimeException5 ()
  642. {
  643. File.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
  644. }
  645. [Test]
  646. [ExpectedException(typeof(ArgumentNullException))]
  647. public void GetLastAccessTimeUtcException1 ()
  648. {
  649. File.GetLastAccessTimeUtc (null as string);
  650. }
  651. [Test]
  652. [ExpectedException(typeof(ArgumentException))]
  653. public void GetLastAccessTimeUtcException2 ()
  654. {
  655. File.GetLastAccessTimeUtc ("");
  656. }
  657. [Test]
  658. [ExpectedException(typeof(IOException))]
  659. public void GetLastAccessTimeUtcException3 ()
  660. {
  661. string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
  662. DeleteFile (path);
  663. File.GetLastAccessTimeUtc (path);
  664. }
  665. [Test]
  666. [ExpectedException(typeof(ArgumentException))]
  667. public void GetLastAccessTimeUtcException4 ()
  668. {
  669. File.GetLastAccessTimeUtc (" ");
  670. }
  671. [Test]
  672. [ExpectedException(typeof(ArgumentException))]
  673. public void GetLastAccessTimeUtcException5 ()
  674. {
  675. File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
  676. }
  677. [Test]
  678. [ExpectedException(typeof(ArgumentNullException))]
  679. public void GetLastWriteTimeException1 ()
  680. {
  681. File.GetLastWriteTime (null as string);
  682. }
  683. [Test]
  684. [ExpectedException(typeof(ArgumentException))]
  685. public void GetLastWriteTimeException2 ()
  686. {
  687. File.GetLastWriteTime ("");
  688. }
  689. [Test]
  690. [ExpectedException(typeof(IOException))]
  691. public void GetLastWriteTimeException3 ()
  692. {
  693. string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
  694. DeleteFile (path);
  695. File.GetLastWriteTime (path);
  696. }
  697. [Test]
  698. [ExpectedException(typeof(ArgumentException))]
  699. public void GetLastWriteTimeException4 ()
  700. {
  701. File.GetLastWriteTime (" ");
  702. }
  703. [Test]
  704. [ExpectedException(typeof(ArgumentException))]
  705. public void GetLastWriteTimeException5 ()
  706. {
  707. File.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
  708. }
  709. [Test]
  710. [ExpectedException(typeof(ArgumentNullException))]
  711. public void GetLastWriteTimeUtcException1 ()
  712. {
  713. File.GetLastWriteTimeUtc (null as string);
  714. }
  715. [Test]
  716. [ExpectedException(typeof(ArgumentException))]
  717. public void GetLastWriteTimeUtcException2 ()
  718. {
  719. File.GetLastAccessTimeUtc ("");
  720. }
  721. [Test]
  722. [ExpectedException(typeof(IOException))]
  723. public void GetLastWriteTimeUtcException3 ()
  724. {
  725. string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
  726. DeleteFile (path);
  727. File.GetLastAccessTimeUtc (path);
  728. }
  729. [Test]
  730. [ExpectedException(typeof(ArgumentException))]
  731. public void GetLastWriteTimeUtcException4 ()
  732. {
  733. File.GetLastAccessTimeUtc (" ");
  734. }
  735. [Test]
  736. [ExpectedException(typeof(ArgumentException))]
  737. public void GetLastWriteTimeUtcException5 ()
  738. {
  739. File.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
  740. }
  741. [Test]
  742. [ExpectedException(typeof(IOException))]
  743. public void FileStreamCloseException ()
  744. {
  745. string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamCloseException";
  746. DeleteFile (path);
  747. FileStream stream = File.Create (path);
  748. File.Delete (path);
  749. }
  750. [Test]
  751. public void FileStreamClose ()
  752. {
  753. string path = TempFolder + Path.DirectorySeparatorChar + "FileStreamClose";
  754. FileStream stream = File.Create (path);
  755. stream.Close ();
  756. File.Delete (path);
  757. }
  758. // SetCreationTime and SetCreationTimeUtc exceptions
  759. [Test]
  760. [ExpectedException(typeof (ArgumentNullException))]
  761. public void SetCreationTimeArgumentNullException1 ()
  762. {
  763. File.SetCreationTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  764. }
  765. [Test]
  766. [ExpectedException(typeof (ArgumentException))]
  767. public void SetCreationTimeArgumenException1 ()
  768. {
  769. File.SetCreationTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
  770. }
  771. [Test]
  772. [ExpectedException(typeof (ArgumentException))]
  773. public void SetCreationTimeArgumenException2 ()
  774. {
  775. File.SetCreationTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  776. }
  777. [Test]
  778. [ExpectedException(typeof (ArgumentException))]
  779. public void SetCreationTimeArgumenException3 ()
  780. {
  781. File.SetCreationTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  782. }
  783. [Test]
  784. [ExpectedException(typeof (FileNotFoundException))]
  785. public void SetCreationTimeFileNotFoundException1 ()
  786. {
  787. string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
  788. DeleteFile (path);
  789. File.SetCreationTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
  790. }
  791. [Test]
  792. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  793. public void SetCreationTimeArgumentOutOfRangeException1 ()
  794. {
  795. string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeArgumentOutOfRangeException1";
  796. DeleteFile (path);
  797. File.Create (path).Close ();
  798. File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  799. }
  800. [Test]
  801. [ExpectedException(typeof (IOException))]
  802. public void SetCreationTimeIOException1 ()
  803. {
  804. string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
  805. DeleteFile (path);
  806. File.Create (path);
  807. File.SetCreationTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  808. }
  809. [Test]
  810. [ExpectedException(typeof (ArgumentNullException))]
  811. public void SetCreationTimeUtcArgumentNullException1 ()
  812. {
  813. File.SetCreationTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  814. }
  815. [Test]
  816. [ExpectedException(typeof (ArgumentException))]
  817. public void SetCreationTimeUtcArgumenException1 ()
  818. {
  819. File.SetCreationTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
  820. }
  821. [Test]
  822. [ExpectedException(typeof (ArgumentException))]
  823. public void SetCreationTimeUtcArgumenException2 ()
  824. {
  825. File.SetCreationTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  826. }
  827. [Test]
  828. [ExpectedException(typeof (ArgumentException))]
  829. public void SetCreationTimeUtcArgumenException3 ()
  830. {
  831. File.SetCreationTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  832. }
  833. [Test]
  834. [ExpectedException(typeof (FileNotFoundException))]
  835. public void SetCreationTimeUtcFileNotFoundException1 ()
  836. {
  837. string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
  838. DeleteFile (path);
  839. File.SetCreationTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
  840. }
  841. [Test]
  842. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  843. public void SetCreationTimeUtcArgumentOutOfRangeException1 ()
  844. {
  845. string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcArgumentOutOfRangeException1";
  846. DeleteFile (path);
  847. File.Create (path).Close ();
  848. File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  849. }
  850. [Test]
  851. [ExpectedException(typeof (IOException))]
  852. public void SetCreationTimeUtcIOException1 ()
  853. {
  854. string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
  855. DeleteFile (path);
  856. File.Create (path);
  857. File.SetCreationTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  858. }
  859. // SetLastAccessTime and SetLastAccessTimeUtc exceptions
  860. [Test]
  861. [ExpectedException(typeof (ArgumentNullException))]
  862. public void SetLastAccessTimeArgumentNullException1 ()
  863. {
  864. File.SetLastAccessTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  865. }
  866. [Test]
  867. [ExpectedException(typeof (ArgumentException))]
  868. public void SetLastAccessTimeArgumenException1 ()
  869. {
  870. File.SetLastAccessTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
  871. }
  872. [Test]
  873. [ExpectedException(typeof (ArgumentException))]
  874. public void SetLastAccessTimeArgumenException2 ()
  875. {
  876. File.SetLastAccessTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  877. }
  878. [Test]
  879. [ExpectedException(typeof (ArgumentException))]
  880. public void SetLastAccessTimeArgumenException3 ()
  881. {
  882. File.SetLastAccessTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  883. }
  884. [Test]
  885. [ExpectedException(typeof (FileNotFoundException))]
  886. public void SetLastAccessTimeFileNotFoundException1 ()
  887. {
  888. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
  889. DeleteFile (path);
  890. File.SetLastAccessTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
  891. }
  892. [Test]
  893. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  894. public void SetLastAccessTimeArgumentOutOfRangeException1 ()
  895. {
  896. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastTimeArgumentOutOfRangeException1";
  897. DeleteFile (path);
  898. File.Create (path).Close ();
  899. File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  900. }
  901. [Test]
  902. [ExpectedException(typeof (IOException))]
  903. public void SetLastAccessTimeIOException1 ()
  904. {
  905. string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
  906. DeleteFile (path);
  907. File.Create (path);
  908. File.SetLastAccessTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  909. }
  910. [Test]
  911. [ExpectedException(typeof (ArgumentNullException))]
  912. public void SetLastAccessTimeUtcArgumentNullException1 ()
  913. {
  914. File.SetLastAccessTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  915. }
  916. [Test]
  917. [ExpectedException(typeof (ArgumentException))]
  918. public void SetCLastAccessTimeUtcArgumenException1 ()
  919. {
  920. File.SetLastAccessTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
  921. }
  922. [Test]
  923. [ExpectedException(typeof (ArgumentException))]
  924. public void SetLastAccessTimeUtcArgumenException2 ()
  925. {
  926. File.SetLastAccessTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  927. }
  928. [Test]
  929. [ExpectedException(typeof (ArgumentException))]
  930. public void SetLastAccessTimeUtcArgumenException3 ()
  931. {
  932. File.SetLastAccessTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  933. }
  934. [Test]
  935. [ExpectedException(typeof (FileNotFoundException))]
  936. public void SetLastAccessTimeUtcFileNotFoundException1 ()
  937. {
  938. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
  939. DeleteFile (path);
  940. File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
  941. }
  942. [Test]
  943. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  944. public void SetLastAccessTimeUtcArgumentOutOfRangeException1 ()
  945. {
  946. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcArgumentOutOfRangeException1";
  947. DeleteFile (path);
  948. File.Create (path).Close ();
  949. File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  950. }
  951. [Test]
  952. [ExpectedException(typeof (IOException))]
  953. public void SetLastAccessTimeUtcIOException1 ()
  954. {
  955. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
  956. DeleteFile (path);
  957. File.Create (path);
  958. File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  959. }
  960. // SetLastWriteTime and SetLastWriteTimeUtc exceptions
  961. [Test]
  962. [ExpectedException(typeof (ArgumentNullException))]
  963. public void SetLastWriteTimeArgumentNullException1 ()
  964. {
  965. File.SetLastWriteTime (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  966. }
  967. [Test]
  968. [ExpectedException(typeof (ArgumentException))]
  969. public void SetLastWriteTimeArgumenException1 ()
  970. {
  971. File.SetLastWriteTime ("", new DateTime (2000, 12, 12, 11, 59, 59));
  972. }
  973. [Test]
  974. [ExpectedException(typeof (ArgumentException))]
  975. public void SetLastWriteTimeArgumenException2 ()
  976. {
  977. File.SetLastWriteTime (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  978. }
  979. [Test]
  980. [ExpectedException(typeof (ArgumentException))]
  981. public void SetLastWriteTimeArgumenException3 ()
  982. {
  983. File.SetLastWriteTime (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  984. }
  985. [Test]
  986. [ExpectedException(typeof (FileNotFoundException))]
  987. public void SetLastWriteTimeFileNotFoundException1 ()
  988. {
  989. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeFileNotFoundException1";
  990. DeleteFile (path);
  991. File.SetLastWriteTime (path, new DateTime (2000, 12, 12, 11, 59, 59));
  992. }
  993. [Test]
  994. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  995. public void SetLastWriteTimeArgumentOutOfRangeException1 ()
  996. {
  997. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeArgumentOutOfRangeException1";
  998. DeleteFile (path);
  999. File.Create (path).Close ();
  1000. File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  1001. }
  1002. [Test]
  1003. [ExpectedException(typeof (IOException))]
  1004. public void SetLastWriteTimeIOException1 ()
  1005. {
  1006. string path = TempFolder + Path.DirectorySeparatorChar + "LastWriteTimeIOException1";
  1007. DeleteFile (path);
  1008. File.Create (path);
  1009. File.SetLastWriteTime (path, new DateTime (1000, 12, 12, 11, 59, 59));
  1010. }
  1011. [Test]
  1012. [ExpectedException(typeof (ArgumentNullException))]
  1013. public void SetLastWriteTimeUtcArgumentNullException1 ()
  1014. {
  1015. File.SetLastWriteTimeUtc (null as string, new DateTime (2000, 12, 12, 11, 59, 59));
  1016. }
  1017. [Test]
  1018. [ExpectedException(typeof (ArgumentException))]
  1019. public void SetCLastWriteTimeUtcArgumenException1 ()
  1020. {
  1021. File.SetLastWriteTimeUtc ("", new DateTime (2000, 12, 12, 11, 59, 59));
  1022. }
  1023. [Test]
  1024. [ExpectedException(typeof (ArgumentException))]
  1025. public void SetLastWriteTimeUtcArgumenException2 ()
  1026. {
  1027. File.SetLastWriteTimeUtc (" ", new DateTime (2000, 12, 12, 11, 59, 59));
  1028. }
  1029. [Test]
  1030. [ExpectedException(typeof (ArgumentException))]
  1031. public void SetLastWriteTimeUtcArgumenException3 ()
  1032. {
  1033. File.SetLastWriteTimeUtc (Path.InvalidPathChars [1].ToString (), new DateTime (2000, 12, 12, 11, 59, 59));
  1034. }
  1035. [Test]
  1036. [ExpectedException(typeof (FileNotFoundException))]
  1037. public void SetLastWriteTimeUtcFileNotFoundException1 ()
  1038. {
  1039. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcFileNotFoundException1";
  1040. DeleteFile (path);
  1041. File.SetLastAccessTimeUtc (path, new DateTime (2000, 12, 12, 11, 59, 59));
  1042. }
  1043. [Test]
  1044. [ExpectedException(typeof (ArgumentOutOfRangeException))]
  1045. public void SetLastWriteTimeUtcArgumentOutOfRangeException1 ()
  1046. {
  1047. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcArgumentOutOfRangeException1";
  1048. DeleteFile (path);
  1049. File.Create (path).Close ();
  1050. File.SetLastWriteTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  1051. }
  1052. [Test]
  1053. [ExpectedException(typeof (IOException))]
  1054. public void SetLastWriteTimeUtcIOException1 ()
  1055. {
  1056. string path = TempFolder + Path.DirectorySeparatorChar + "SetLastWriteTimeUtcIOException1";
  1057. DeleteFile (path);
  1058. File.Create (path);
  1059. File.SetLastAccessTimeUtc (path, new DateTime (1000, 12, 12, 11, 59, 59));
  1060. }
  1061. private void DeleteFile (string path)
  1062. {
  1063. if (File.Exists (path))
  1064. File.Delete (path);
  1065. }
  1066. }
  1067. }