FileTest.cs 42 KB

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