FileTest.cs 42 KB

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