DirectoryTest.cs 28 KB

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