FileTest.cs 41 KB

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