DirectoryTest.cs 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. //
  2. // System.IO.Directory
  3. //
  4. // Authors:
  5. // Ville Palo ([email protected])
  6. //
  7. // (C) 2003 Ville Palo
  8. //
  9. using NUnit.Framework;
  10. using System.IO;
  11. using System.Text;
  12. using System;
  13. using System.Globalization;
  14. using System.Threading;
  15. namespace MonoTests.System.IO {
  16. [TestFixture]
  17. public class DirectoryTest {
  18. public DirectoryTest ()
  19. {
  20. }
  21. [SetUp]
  22. public void SetUp ()
  23. {
  24. Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
  25. }
  26. ~DirectoryTest ()
  27. {
  28. // just in case, remove all of the used files
  29. RemoveAllDirs ();
  30. }
  31. [Test]
  32. public void CreateDirectory ()
  33. {
  34. DeleteDirectory (".DirectoryTest.Test.1");
  35. DirectoryInfo info = Directory.CreateDirectory (".DirectoryTest.Test.1");
  36. Assertion.AssertEquals ("test#01", true, info.Exists);
  37. Assertion.AssertEquals ("test#02", ".1", info.Extension);
  38. Assertion.AssertEquals ("test#03", true, info.FullName.EndsWith (".DirectoryTest.Test.1"));
  39. Assertion.AssertEquals ("test#04", ".DirectoryTest.Test.1", info.Name);
  40. Assertion.AssertEquals ("test#05", true, Directory.GetCurrentDirectory ().EndsWith (info.Parent.Name));
  41. DeleteDirectory (".DirectoryTest.Test.1");
  42. }
  43. [Test]
  44. [ExpectedException(typeof(ArgumentException))]
  45. public void CreateDirectoryNotSupportedException ()
  46. {
  47. DeleteDirectory (":");
  48. DirectoryInfo info = Directory.CreateDirectory (":");
  49. DeleteDirectory (":");
  50. }
  51. [Test]
  52. [ExpectedException(typeof(ArgumentNullException))]
  53. public void CreateDirectoryArgumentNullException ()
  54. {
  55. DirectoryInfo info = Directory.CreateDirectory (null as string);
  56. }
  57. [Test]
  58. [ExpectedException(typeof(ArgumentException))]
  59. public void CreateDirectoryArgumentException1 ()
  60. {
  61. DirectoryInfo info = Directory.CreateDirectory ("");
  62. }
  63. [Test]
  64. [ExpectedException(typeof(ArgumentException))]
  65. public void CreateDirectoryArgumentException2 ()
  66. {
  67. DirectoryInfo info = Directory.CreateDirectory (" ");
  68. }
  69. [Test]
  70. [ExpectedException(typeof(ArgumentException))]
  71. public void CreateDirectoryArgumentException3 ()
  72. {
  73. DeleteDirectory (".DirectoryTest.Test.2");
  74. string path = ".DirectoryTest.Test.";
  75. path += Path.InvalidPathChars [0];
  76. path += ".2";
  77. DirectoryInfo info = Directory.CreateDirectory (path);
  78. DeleteDirectory (".DirectoryTest.Test.2");
  79. }
  80. [Test]
  81. public void Delete ()
  82. {
  83. string path = ".DirectoryTest.Test.Delete.1";
  84. DeleteDirectory (path);
  85. Directory.CreateDirectory (path);
  86. Assertion.AssertEquals ("test#01", true, Directory.Exists (path));
  87. Directory.CreateDirectory (path + "/DirectoryTest.Test.Delete.1.2");
  88. Assertion.AssertEquals ("test#02", true, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
  89. Directory.Delete (path + "/DirectoryTest.Test.Delete.1.2");
  90. Assertion.AssertEquals ("test#03", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
  91. Assertion.AssertEquals ("test#04", true, Directory.Exists (path));
  92. Directory.Delete (path);
  93. Assertion.AssertEquals ("test#05", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
  94. Assertion.AssertEquals ("test#06", false, Directory.Exists (path));
  95. Directory.CreateDirectory (path);
  96. Directory.CreateDirectory (path + "/DirectoryTest.Test.Delete.1.2");
  97. Assertion.AssertEquals ("test#07", true, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
  98. Assertion.AssertEquals ("test#08", true, Directory.Exists (path));
  99. Directory.Delete (path, true);
  100. Assertion.AssertEquals ("test#09", false, Directory.Exists (path + "/DirectoryTest.Test.Delete.1.2"));
  101. Assertion.AssertEquals ("test#10", false, Directory.Exists (path));
  102. }
  103. [Test]
  104. [ExpectedException(typeof(ArgumentException))]
  105. public void DeleteArgumentException ()
  106. {
  107. Directory.Delete ("");
  108. }
  109. [Test]
  110. [ExpectedException(typeof(ArgumentException))]
  111. public void DeleteArgumentException2 ()
  112. {
  113. Directory.Delete (" ");
  114. }
  115. [Test]
  116. [ExpectedException(typeof(ArgumentException))]
  117. public void DeleteArgumentException3 ()
  118. {
  119. string path = ".DirectoryTest.Test.4";
  120. DeleteDirectory (path);
  121. path += Path.InvalidPathChars [0];
  122. Directory.Delete (path);
  123. }
  124. [Test]
  125. [ExpectedException(typeof(ArgumentNullException))]
  126. public void DeleteArgumentNullException ()
  127. {
  128. Directory.Delete (null as string);
  129. }
  130. [Test]
  131. [ExpectedException(typeof(DirectoryNotFoundException))]
  132. public void DeleteDirectoryNotFoundException ()
  133. {
  134. string path = ".DirectoryTest.Test.5";
  135. DeleteDirectory (path);
  136. Directory.Delete (path);
  137. }
  138. [Test]
  139. [ExpectedException(typeof(IOException))]
  140. public void DeleteArgumentException4 ()
  141. {
  142. string path = ".DirectoryTest.Test.6";
  143. DeleteDirectory (path);
  144. Directory.CreateDirectory (path);
  145. File.Create (path + "/.DirectoryTest.Test.6");
  146. DeleteDirectory (path);
  147. }
  148. [Test]
  149. public void Exists ()
  150. {
  151. Assertion.AssertEquals ("test#01", false, Directory.Exists (null as string));
  152. }
  153. [Test]
  154. [ExpectedException(typeof(ArgumentNullException))]
  155. public void GetCreationTimeException1 ()
  156. {
  157. Directory.GetCreationTime (null as string);
  158. }
  159. [Test]
  160. [ExpectedException(typeof(ArgumentException))]
  161. public void GetCreationTimeException2 ()
  162. {
  163. Directory.GetCreationTime ("");
  164. }
  165. [Test]
  166. [ExpectedException(typeof(IOException))]
  167. public void GetCreationTimeException3 ()
  168. {
  169. string path = ".DirectoryTest.GetCreationTime.1";
  170. DeleteDirectory (path);
  171. Directory.GetCreationTime (path);
  172. }
  173. [Test]
  174. [ExpectedException(typeof(ArgumentException))]
  175. public void GetCreationTimeException4 ()
  176. {
  177. Directory.GetCreationTime (" ");
  178. }
  179. [Test]
  180. [ExpectedException(typeof(ArgumentException))]
  181. public void GetCreationTimeException5 ()
  182. {
  183. Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
  184. }
  185. [Test]
  186. [ExpectedException(typeof(ArgumentNullException))]
  187. public void GetCreationTimeUtcException1 ()
  188. {
  189. Directory.GetCreationTimeUtc (null as string);
  190. }
  191. [Test]
  192. [ExpectedException(typeof(ArgumentException))]
  193. public void GetCreationTimeUtcException2 ()
  194. {
  195. Directory.GetCreationTimeUtc ("");
  196. }
  197. [Test]
  198. [ExpectedException(typeof(IOException))]
  199. public void GetCreationTimeUtcException3 ()
  200. {
  201. string path = ".DirectoryTest.GetCreationTimeUtc.1";
  202. DeleteDirectory (path);
  203. Directory.GetCreationTimeUtc (path);
  204. }
  205. [Test]
  206. [ExpectedException(typeof(ArgumentException))]
  207. public void GetCreationTimeUtcException4 ()
  208. {
  209. Directory.GetCreationTimeUtc (" ");
  210. }
  211. [Test]
  212. [ExpectedException(typeof(ArgumentException))]
  213. public void GetCreationTimeUtcException5 ()
  214. {
  215. Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
  216. }
  217. [Test]
  218. [ExpectedException(typeof(ArgumentNullException))]
  219. public void GetLastAccessTimeException1 ()
  220. {
  221. Directory.GetLastAccessTime (null as string);
  222. }
  223. [Test]
  224. [ExpectedException(typeof(ArgumentException))]
  225. public void GetLastAccessTimeException2 ()
  226. {
  227. Directory.GetLastAccessTime ("");
  228. }
  229. [Test]
  230. [ExpectedException(typeof(IOException))]
  231. public void GetLastAccessTimeException3 ()
  232. {
  233. string path = ".DirectoryTest.GetLastAccessTime.1";
  234. DeleteDirectory (path);
  235. Directory.GetLastAccessTime (path);
  236. }
  237. [Test]
  238. [ExpectedException(typeof(ArgumentException))]
  239. public void GetLastAccessTimeException4 ()
  240. {
  241. Directory.GetLastAccessTime (" ");
  242. }
  243. [Test]
  244. [ExpectedException(typeof(ArgumentException))]
  245. public void GetLastAccessTimeException5 ()
  246. {
  247. Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
  248. }
  249. [Test]
  250. [ExpectedException(typeof(ArgumentNullException))]
  251. public void GetLastAccessTimeUtcException1 ()
  252. {
  253. Directory.GetLastAccessTimeUtc (null as string);
  254. }
  255. [Test]
  256. [ExpectedException(typeof(ArgumentException))]
  257. public void GetLastAccessTimeUtcException2 ()
  258. {
  259. Directory.GetLastAccessTimeUtc ("");
  260. }
  261. [Test]
  262. [ExpectedException(typeof(IOException))]
  263. public void GetLastAccessTimeUtcException3 ()
  264. {
  265. string path = ".DirectoryTest.GetLastAccessTimeUtc.1";
  266. DeleteDirectory (path);
  267. Directory.GetLastAccessTimeUtc (path);
  268. }
  269. [Test]
  270. [ExpectedException(typeof(ArgumentException))]
  271. public void GetLastAccessTimeUtcException4 ()
  272. {
  273. Directory.GetLastAccessTimeUtc (" ");
  274. }
  275. [Test]
  276. [ExpectedException(typeof(ArgumentException))]
  277. public void GetLastAccessTimeUtcException5 ()
  278. {
  279. Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
  280. }
  281. [Test]
  282. [ExpectedException(typeof(ArgumentNullException))]
  283. public void GetLastWriteTimeException1 ()
  284. {
  285. Directory.GetLastWriteTime (null as string);
  286. }
  287. [Test]
  288. [ExpectedException(typeof(ArgumentException))]
  289. public void GetLastWriteTimeException2 ()
  290. {
  291. Directory.GetLastWriteTime ("");
  292. }
  293. [Test]
  294. [ExpectedException(typeof(IOException))]
  295. public void GetLastWriteTimeException3 ()
  296. {
  297. string path = ".DirectoryTest.GetLastWriteTime.1";
  298. DeleteDirectory (path);
  299. Directory.GetLastWriteTime (path);
  300. }
  301. [Test]
  302. [ExpectedException(typeof(ArgumentException))]
  303. public void GetLastWriteTimeException4 ()
  304. {
  305. Directory.GetLastWriteTime (" ");
  306. }
  307. [Test]
  308. [ExpectedException(typeof(ArgumentException))]
  309. public void GetLastWriteTimeException5 ()
  310. {
  311. Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
  312. }
  313. [Test]
  314. [ExpectedException(typeof(ArgumentNullException))]
  315. public void GetLastWriteTimeUtcException1 ()
  316. {
  317. Directory.GetLastWriteTimeUtc (null as string);
  318. }
  319. [Test]
  320. [ExpectedException(typeof(ArgumentException))]
  321. public void GetLastWriteTimeUtcException2 ()
  322. {
  323. Directory.GetLastAccessTimeUtc ("");
  324. }
  325. [Test]
  326. [ExpectedException(typeof(IOException))]
  327. public void GetLastWriteTimeUtcException3 ()
  328. {
  329. string path = ".DirectoryTest.GetLastWriteTimeUtc.1";
  330. DeleteDirectory (path);
  331. Directory.GetLastAccessTimeUtc (path);
  332. }
  333. [Test]
  334. [ExpectedException(typeof(ArgumentException))]
  335. public void GetLastWriteTimeUtcException4 ()
  336. {
  337. Directory.GetLastAccessTimeUtc (" ");
  338. }
  339. [Test]
  340. [ExpectedException(typeof(ArgumentException))]
  341. public void GetLastWriteTimeUtcException5 ()
  342. {
  343. Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
  344. }
  345. [Test]
  346. public void Move ()
  347. {
  348. string path = ".DirectoryTest.Test.9";
  349. string path2 = ".DirectoryTest.Test.10";
  350. DeleteDirectory (path);
  351. DeleteDirectory (path2);
  352. Directory.CreateDirectory (path);
  353. Directory.CreateDirectory (path + "/" + path);
  354. Assertion.AssertEquals ("test#01", true, Directory.Exists (path + "/" + path));
  355. Directory.Move (path, path2);
  356. Assertion.AssertEquals ("test#02", false, Directory.Exists (path + "/" + path));
  357. Assertion.AssertEquals ("test#03", true, Directory.Exists (path2 + "/" + path));
  358. if (Directory.Exists (path2 + "/" + path))
  359. Directory.Delete (path2 + "/" + path, true);
  360. }
  361. [Test]
  362. [ExpectedException(typeof(IOException))]
  363. public void MoveException1 ()
  364. {
  365. string path = ".DirectoryTest.Test.8";
  366. DeleteDirectory (path);
  367. Directory.Move (path, path);
  368. }
  369. [Test]
  370. [ExpectedException(typeof(ArgumentException))]
  371. public void MoveException2 ()
  372. {
  373. string path = ".DirectoryTest.Test.11";
  374. DeleteDirectory (path);
  375. Directory.Move ("", path);
  376. }
  377. [Test]
  378. [ExpectedException(typeof(ArgumentException))]
  379. public void MoveException3 ()
  380. {
  381. string path = ".DirectoryTest.Test.12";
  382. DeleteDirectory (path);
  383. Directory.Move (" ", path);
  384. }
  385. [Test]
  386. [ExpectedException(typeof(ArgumentException))]
  387. public void MoveException4 ()
  388. {
  389. string path = ".DirectoryTest.Test.13";
  390. path += Path.InvalidPathChars [0];
  391. string path2 = ".DirectoryTest.Test.13";
  392. DeleteDirectory (path);
  393. DeleteDirectory (path2);
  394. Directory.CreateDirectory (path2);
  395. Directory.Move (path2, path);
  396. }
  397. [Test]
  398. [ExpectedException(typeof(DirectoryNotFoundException))]
  399. public void MoveException5 ()
  400. {
  401. string path = ".DirectoryTest.Test.14";
  402. DeleteDirectory (path);
  403. Directory.Move (path, path + "Test.Test");
  404. }
  405. [Test]
  406. [ExpectedException(typeof(IOException))]
  407. public void MoveException6 ()
  408. {
  409. string path = ".DirectoryTest.Test.15";
  410. DeleteDirectory (path);
  411. Directory.CreateDirectory (path);
  412. Directory.Move (path, path + "/" + path);
  413. }
  414. [Test]
  415. [ExpectedException(typeof(IOException))]
  416. public void MoveException7 ()
  417. {
  418. string path = ".DirectoryTest.Test.16";
  419. string path2 = ".DirectoryTest.Test.17";
  420. DeleteDirectory (path);
  421. DeleteDirectory (path2);
  422. Directory.CreateDirectory (path);
  423. Directory.CreateDirectory (path2);
  424. Directory.Move (path, path2);
  425. DeleteDirectory (path);
  426. DeleteDirectory (path2);
  427. }
  428. [Test]
  429. public void CreationTime ()
  430. {
  431. string path = ".DirectoryTest.CreationTime.1";
  432. DeleteDirectory (path);
  433. Directory.CreateDirectory (path);
  434. Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
  435. DateTime time = Directory.GetCreationTime (path);
  436. Assertion.AssertEquals ("test#01", 2003, time.Year);
  437. Assertion.AssertEquals ("test#02", 6, time.Month);
  438. Assertion.AssertEquals ("test#03", 4, time.Day);
  439. Assertion.AssertEquals ("test#04", 6, time.Hour);
  440. Assertion.AssertEquals ("test#05", 4, time.Minute);
  441. Assertion.AssertEquals ("test#06", 0, time.Second);
  442. time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
  443. Assertion.AssertEquals ("test#07", 2003, time.Year);
  444. Assertion.AssertEquals ("test#08", 6, time.Month);
  445. Assertion.AssertEquals ("test#09", 4, time.Day);
  446. Assertion.AssertEquals ("test#10", 6, time.Hour);
  447. Assertion.AssertEquals ("test#11", 4, time.Minute);
  448. Assertion.AssertEquals ("test#12", 0, time.Second);
  449. Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
  450. time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
  451. Assertion.AssertEquals ("test#13", 2003, time.Year);
  452. Assertion.AssertEquals ("test#14", 6, time.Month);
  453. Assertion.AssertEquals ("test#15", 4, time.Day);
  454. Assertion.AssertEquals ("test#16", 6, time.Hour);
  455. Assertion.AssertEquals ("test#17", 4, time.Minute);
  456. Assertion.AssertEquals ("test#18", 0, time.Second);
  457. time = Directory.GetCreationTimeUtc (path);
  458. Assertion.AssertEquals ("test#19", 2003, time.Year);
  459. Assertion.AssertEquals ("test#20", 6, time.Month);
  460. Assertion.AssertEquals ("test#21", 4, time.Day);
  461. Assertion.AssertEquals ("test#22", 6, time.Hour);
  462. Assertion.AssertEquals ("test#23", 4, time.Minute);
  463. Assertion.AssertEquals ("test#24", 0, time.Second);
  464. DeleteDirectory (path);
  465. }
  466. [Test]
  467. public void LastAccessTime ()
  468. {
  469. string path = ".DirectoryTest.AccessTime.1";
  470. DeleteDirectory (path);
  471. Directory.CreateDirectory (path);
  472. Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
  473. DateTime time = Directory.GetLastAccessTime (path);
  474. Assertion.AssertEquals ("test#01", 2003, time.Year);
  475. Assertion.AssertEquals ("test#02", 6, time.Month);
  476. Assertion.AssertEquals ("test#03", 4, time.Day);
  477. Assertion.AssertEquals ("test#04", 6, time.Hour);
  478. Assertion.AssertEquals ("test#05", 4, time.Minute);
  479. Assertion.AssertEquals ("test#06", 0, time.Second);
  480. time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
  481. Assertion.AssertEquals ("test#07", 2003, time.Year);
  482. Assertion.AssertEquals ("test#08", 6, time.Month);
  483. Assertion.AssertEquals ("test#09", 4, time.Day);
  484. Assertion.AssertEquals ("test#10", 6, time.Hour);
  485. Assertion.AssertEquals ("test#11", 4, time.Minute);
  486. Assertion.AssertEquals ("test#12", 0, time.Second);
  487. Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
  488. time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
  489. Assertion.AssertEquals ("test#13", 2003, time.Year);
  490. Assertion.AssertEquals ("test#14", 6, time.Month);
  491. Assertion.AssertEquals ("test#15", 4, time.Day);
  492. Assertion.AssertEquals ("test#16", 6, time.Hour);
  493. Assertion.AssertEquals ("test#17", 4, time.Minute);
  494. Assertion.AssertEquals ("test#18", 0, time.Second);
  495. time = Directory.GetLastAccessTimeUtc (path);
  496. Assertion.AssertEquals ("test#19", 2003, time.Year);
  497. Assertion.AssertEquals ("test#20", 6, time.Month);
  498. Assertion.AssertEquals ("test#21", 4, time.Day);
  499. Assertion.AssertEquals ("test#22", 6, time.Hour);
  500. Assertion.AssertEquals ("test#23", 4, time.Minute);
  501. Assertion.AssertEquals ("test#24", 0, time.Second);
  502. DeleteDirectory (path);
  503. }
  504. [Test]
  505. public void LastWriteTime ()
  506. {
  507. string path = ".DirectoryTest.WriteTime.1";
  508. DeleteDirectory (path);
  509. Directory.CreateDirectory (path);
  510. Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
  511. DateTime time = Directory.GetLastWriteTime (path);
  512. Assertion.AssertEquals ("test#01", 2003, time.Year);
  513. Assertion.AssertEquals ("test#02", 6, time.Month);
  514. Assertion.AssertEquals ("test#03", 4, time.Day);
  515. Assertion.AssertEquals ("test#04", 6, time.Hour);
  516. Assertion.AssertEquals ("test#05", 4, time.Minute);
  517. Assertion.AssertEquals ("test#06", 0, time.Second);
  518. time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
  519. Assertion.AssertEquals ("test#07", 2003, time.Year);
  520. Assertion.AssertEquals ("test#08", 6, time.Month);
  521. Assertion.AssertEquals ("test#09", 4, time.Day);
  522. Assertion.AssertEquals ("test#10", 6, time.Hour);
  523. Assertion.AssertEquals ("test#11", 4, time.Minute);
  524. Assertion.AssertEquals ("test#12", 0, time.Second);
  525. Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
  526. time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
  527. Assertion.AssertEquals ("test#13", 2003, time.Year);
  528. Assertion.AssertEquals ("test#14", 6, time.Month);
  529. Assertion.AssertEquals ("test#15", 4, time.Day);
  530. Assertion.AssertEquals ("test#16", 6, time.Hour);
  531. Assertion.AssertEquals ("test#17", 4, time.Minute);
  532. Assertion.AssertEquals ("test#18", 0, time.Second);
  533. time = Directory.GetLastWriteTimeUtc (path);
  534. Assertion.AssertEquals ("test#19", 2003, time.Year);
  535. Assertion.AssertEquals ("test#20", 6, time.Month);
  536. Assertion.AssertEquals ("test#21", 4, time.Day);
  537. Assertion.AssertEquals ("test#22", 6, time.Hour);
  538. Assertion.AssertEquals ("test#23", 4, time.Minute);
  539. Assertion.AssertEquals ("test#24", 0, time.Second);
  540. DeleteDirectory (path);
  541. }
  542. [Test]
  543. [ExpectedException(typeof(ArgumentNullException))]
  544. public void SetLastWriteTimeException1 ()
  545. {
  546. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  547. Directory.SetLastWriteTime (null as string, time);
  548. }
  549. [Test]
  550. [ExpectedException(typeof(ArgumentException))]
  551. public void SetLastWriteTimeException2 ()
  552. {
  553. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  554. Directory.SetLastWriteTime ("", time);
  555. }
  556. [Test]
  557. [ExpectedException(typeof(FileNotFoundException))]
  558. public void SetLastWriteTimeException3 ()
  559. {
  560. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  561. string path = ".DirectoryTest.SetLastWriteTime.2";
  562. DeleteDirectory (path);
  563. Directory.SetLastWriteTime (path, time);
  564. }
  565. [Test]
  566. [ExpectedException(typeof(ArgumentException))]
  567. public void SetLastWriteTimeException4 ()
  568. {
  569. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  570. Directory.SetLastWriteTime (" ", time);
  571. }
  572. [Test]
  573. [ExpectedException(typeof(ArgumentException))]
  574. public void SetLastWriteTimeException5 ()
  575. {
  576. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  577. Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
  578. }
  579. [Test]
  580. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  581. public void SetLastWriteTimeException6 ()
  582. {
  583. DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
  584. string path = ".DirectoryTest.SetLastWriteTime.1";
  585. if (!Directory.Exists (path))
  586. Directory.CreateDirectory (path);
  587. Directory.SetLastWriteTime (path, time);
  588. }
  589. [Test]
  590. [ExpectedException(typeof(ArgumentNullException))]
  591. public void SetLastWriteTimeUtcException1 ()
  592. {
  593. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  594. Directory.SetLastWriteTimeUtc (null as string, time);
  595. }
  596. [Test]
  597. [ExpectedException(typeof(ArgumentException))]
  598. public void SetLastWriteTimeUtcException2 ()
  599. {
  600. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  601. Directory.SetLastWriteTimeUtc ("", time);
  602. }
  603. [Test]
  604. [ExpectedException(typeof(FileNotFoundException))]
  605. public void SetLastWriteTimeUtcException3 ()
  606. {
  607. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  608. string path = ".DirectoryTest.SetLastWriteTimeUtc.2";
  609. DeleteDirectory (path);
  610. Directory.SetLastWriteTimeUtc (path, time);
  611. }
  612. [Test]
  613. [ExpectedException(typeof(ArgumentException))]
  614. public void SetLastWriteTimeUtcException4 ()
  615. {
  616. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  617. Directory.SetLastWriteTimeUtc (" ", time);
  618. }
  619. [Test]
  620. [ExpectedException(typeof(ArgumentException))]
  621. public void SetLastWriteTimeUtcException5 ()
  622. {
  623. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  624. Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
  625. }
  626. [Test]
  627. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  628. public void SetLastWriteTimeUtcException6 ()
  629. {
  630. DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
  631. string path = ".DirectoryTest.SetLastWriteTimeUtc.1";
  632. if (!Directory.Exists (path))
  633. Directory.CreateDirectory (path);
  634. Directory.SetLastWriteTimeUtc (path, time);
  635. }
  636. [Test]
  637. [ExpectedException(typeof(ArgumentNullException))]
  638. public void SetLastAccessTimeException1 ()
  639. {
  640. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  641. Directory.SetLastAccessTime (null as string, time);
  642. }
  643. [Test]
  644. [ExpectedException(typeof(ArgumentException))]
  645. public void SetLastAccessTimeException2 ()
  646. {
  647. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  648. Directory.SetLastAccessTime ("", time);
  649. }
  650. [Test]
  651. [ExpectedException(typeof(FileNotFoundException))]
  652. public void SetLastAccessTimeException3 ()
  653. {
  654. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  655. string path = ".DirectoryTest.SetLastAccessTime.2";
  656. DeleteDirectory (path);
  657. Directory.SetLastAccessTime (path, time);
  658. }
  659. [Test]
  660. [ExpectedException(typeof(ArgumentException))]
  661. public void SetLastAccessTimeException4 ()
  662. {
  663. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  664. Directory.SetLastAccessTime (" ", time);
  665. }
  666. [Test]
  667. [ExpectedException(typeof(ArgumentException))]
  668. public void SetLastAccessTimeException5 ()
  669. {
  670. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  671. Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
  672. }
  673. [Test]
  674. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  675. public void SetLastAccessTimeException6 ()
  676. {
  677. DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
  678. string path = ".DirectoryTest.SetLastAccessTime.1";
  679. if (!Directory.Exists (path))
  680. Directory.CreateDirectory (path);
  681. Directory.SetLastAccessTime (path, time);
  682. }
  683. [Test]
  684. [ExpectedException(typeof(ArgumentNullException))]
  685. public void SetLastAccessTimeUtcException1 ()
  686. {
  687. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  688. Directory.SetLastAccessTimeUtc (null as string, time);
  689. }
  690. [Test]
  691. [ExpectedException(typeof(ArgumentException))]
  692. public void SetLastAccessTimeUtcException2 ()
  693. {
  694. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  695. Directory.SetLastAccessTimeUtc ("", time);
  696. }
  697. [Test]
  698. [ExpectedException(typeof(FileNotFoundException))]
  699. public void SetLastAccessTimeUtcException3 ()
  700. {
  701. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  702. string path = ".DirectoryTest.SetLastAccessTimeUtc.2";
  703. DeleteDirectory (path);
  704. Directory.SetLastAccessTimeUtc (path, time);
  705. }
  706. [Test]
  707. [ExpectedException(typeof(ArgumentException))]
  708. public void SetLastAccessTimeUtcException4 ()
  709. {
  710. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  711. Directory.SetLastAccessTimeUtc (" ", time);
  712. }
  713. [Test]
  714. [ExpectedException(typeof(ArgumentException))]
  715. public void SetLastAccessTimeUtcException5 ()
  716. {
  717. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  718. Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
  719. }
  720. [Test]
  721. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  722. public void SetLastAccessTimeUtcException6 ()
  723. {
  724. DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
  725. string path = ".DirectoryTest.SetLastAccessTimeUtc.1";
  726. if (!Directory.Exists (path))
  727. Directory.CreateDirectory (path);
  728. Directory.SetLastAccessTimeUtc (path, time);
  729. }
  730. [ExpectedException(typeof(ArgumentNullException))]
  731. public void SetCreationTimeException1 ()
  732. {
  733. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  734. Directory.SetCreationTime (null as string, time);
  735. }
  736. [Test]
  737. [ExpectedException(typeof(ArgumentException))]
  738. public void SetCreationTimeException2 ()
  739. {
  740. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  741. Directory.SetCreationTime ("", time);
  742. }
  743. [Test]
  744. [ExpectedException(typeof(FileNotFoundException))]
  745. public void SetCreationTimeException3 ()
  746. {
  747. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  748. string path = ".DirectoryTest.SetCreationTime.2";
  749. DeleteDirectory (path);
  750. Directory.SetCreationTime (path, time);
  751. }
  752. [Test]
  753. [ExpectedException(typeof(ArgumentException))]
  754. public void SetCreationTimeException4 ()
  755. {
  756. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  757. Directory.SetCreationTime (" ", time);
  758. }
  759. [Test]
  760. [ExpectedException(typeof(ArgumentException))]
  761. public void SetCreationTimeException5 ()
  762. {
  763. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  764. Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
  765. }
  766. [Test]
  767. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  768. public void SetCreationTimeException6 ()
  769. {
  770. DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
  771. string path = ".DirectoryTest.SetCreationTime.1";
  772. if (!Directory.Exists (path))
  773. Directory.CreateDirectory (path);
  774. Directory.SetCreationTime (path, time);
  775. }
  776. [Test]
  777. [ExpectedException(typeof(ArgumentNullException))]
  778. public void SetCreationTimeUtcException1 ()
  779. {
  780. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  781. Directory.SetCreationTimeUtc (null as string, time);
  782. }
  783. [Test]
  784. [ExpectedException(typeof(ArgumentException))]
  785. public void SetCreationTimeUtcException2 ()
  786. {
  787. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  788. Directory.SetCreationTimeUtc ("", time);
  789. }
  790. [Test]
  791. [ExpectedException(typeof(FileNotFoundException))]
  792. public void SetCreationTimeUtcException3 ()
  793. {
  794. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  795. string path = ".DirectoryTest.SetLastAccessTimeUtc.2";
  796. DeleteDirectory (path);
  797. Directory.SetCreationTimeUtc (path, time);
  798. }
  799. [Test]
  800. [ExpectedException(typeof(ArgumentException))]
  801. public void SetCreationTimeUtcException4 ()
  802. {
  803. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  804. Directory.SetCreationTimeUtc (" ", time);
  805. }
  806. [Test]
  807. [ExpectedException(typeof(ArgumentException))]
  808. public void SetCreationTimeUtcException5 ()
  809. {
  810. DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
  811. Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
  812. }
  813. [Test]
  814. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  815. public void SetCreationTimeUtcException6 ()
  816. {
  817. DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
  818. string path = ".DirectoryTest.SetLastAccessTimeUtc.1";
  819. if (!Directory.Exists (path))
  820. Directory.CreateDirectory (path);
  821. Directory.SetCreationTimeUtc (path, time);
  822. }
  823. private void DeleteDirectory (string path)
  824. {
  825. if (Directory.Exists (path))
  826. Directory.Delete (path, true);
  827. }
  828. private void RemoveAllDirs ()
  829. {
  830. DeleteDirectory (".DirectoryTest.Test.1");
  831. DeleteDirectory (".DirectoryTest.Test.2");
  832. DeleteDirectory (".DirectoryTest.Test.Delete.1");
  833. DeleteDirectory (".DirectoryTest.Test.3");
  834. DeleteDirectory (".DirectoryTest.Test.4");
  835. DeleteDirectory (".DirectoryTest.Test.5");
  836. DeleteDirectory (".DirectoryTest.Test.6");
  837. DeleteDirectory (".DirectoryTest.Test.7");
  838. DeleteDirectory (".DirectoryTest.Test.8");
  839. DeleteDirectory (".DirectoryTest.Test.9");
  840. DeleteDirectory (".DirectoryTest.Test.10");
  841. DeleteDirectory (".DirectoryTest.Test.11");
  842. DeleteDirectory (".DirectoryTest.Test.12");
  843. DeleteDirectory (".DirectoryTest.Test.13");
  844. DeleteDirectory (".DirectoryTest.Test.14");
  845. DeleteDirectory (".DirectoryTest.Test.15");
  846. DeleteDirectory (".DirectoryTest.Test.16");
  847. DeleteDirectory (".DirectoryTest.Test.17");
  848. DeleteDirectory (".DirectoryTest.Test.18");
  849. DeleteDirectory (".DirectoryTest.CreationTime.1");
  850. DeleteDirectory (".DirectoryTest.AccessTime.1");
  851. DeleteDirectory (".DirectoryTest.WriteTime.1");
  852. DeleteDirectory (".DirectoryTest.SetLastWriteTime.1");
  853. DeleteDirectory (".DirectoryTest.SetLastWriteTime.2");
  854. DeleteDirectory (".DirectoryTest.SetLastWriteTimeUtc.1");
  855. DeleteDirectory (".DirectoryTest.SetLastWriteTimeUtc.2");
  856. DeleteDirectory (".DirectoryTest.GetLastWriteTime.1");
  857. DeleteDirectory (".DirectoryTest.GetLastWriteTime.2");
  858. DeleteDirectory (".DirectoryTest.GetLastWriteTimeUtc.1");
  859. DeleteDirectory (".DirectoryTest.GetLastWriteTimeUtc.2");
  860. DeleteDirectory (".DirectoryTest.GetCreationTimeUtc.1");
  861. DeleteDirectory (".DirectoryTest.GetCreationTime.1");
  862. DeleteDirectory (".DirectoryTest.GetLastAccessTimeUtc.1");
  863. DeleteDirectory (".DirectoryTest.GetLastAccessTime.1");
  864. DeleteDirectory (".DirectoryTest.SetLastAccessTime.1");
  865. DeleteDirectory (".DirectoryTest.SetLastAccessTime.2");
  866. DeleteDirectory (".DirectoryTest.SetLastAccessTimeUtc.1");
  867. DeleteDirectory (".DirectoryTest.SetLastAccessTimeUtc.2");
  868. DeleteDirectory (".DirectoryTest.SetCreationTime.1");
  869. DeleteDirectory (".DirectoryTest.SetCreationTime.2");
  870. DeleteDirectory (".DirectoryTest.SetCreationTimeUtc.1");
  871. DeleteDirectory (".DirectoryTest.SetCreationTimeUtc.2");
  872. }
  873. }
  874. }