**** Merged from MCS ****
[mono-project.git] / mcs / class / corlib / Test / System.IO / DirectoryTest.cs
blob5b168e315486b3d1258c6a3a4507c7d9ed3f7e10
1 //
2 // System.IO.Directory
3 //
4 // Authors:
5 // Ville Palo (vi64pa@kolumbus.fi)
6 //
7 // (C) 2003 Ville Palo
8 //
9 // TODO: Find out why ArgumentOutOfRange tests does not release directories properly
12 using NUnit.Framework;
13 using System.IO;
14 using System.Text;
15 using System;
16 using System.Globalization;
17 using System.Threading;
19 namespace MonoTests.System.IO {
21 [TestFixture]
22 public class DirectoryTest : Assertion {
24 string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
25 static readonly char DSC = Path.DirectorySeparatorChar;
27 [SetUp]
28 public void SetUp ()
30 if (!Directory.Exists (TempFolder))
31 Directory.CreateDirectory (TempFolder);
33 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
36 [TearDown]
37 public void TearDown () {
38 if (Directory.Exists (TempFolder))
39 Directory.Delete (TempFolder, true);
42 [Test]
43 public void CreateDirectory ()
45 string path = TempFolder + DSC + "DirectoryTest.Test.1";
46 DeleteDirectory (path);
47 try {
48 DirectoryInfo info = Directory.CreateDirectory (path);
49 AssertEquals ("test#01", true, info.Exists);
50 AssertEquals ("test#02", ".1", info.Extension);
51 AssertEquals ("test#03", true, info.FullName.EndsWith ("DirectoryTest.Test.1"));
52 AssertEquals ("test#04", "DirectoryTest.Test.1", info.Name);
53 } finally {
54 DeleteDirectory (path);
58 [Test]
59 [ExpectedException(typeof(ArgumentException))]
60 public void CreateDirectoryNotSupportedException ()
62 DeleteDirectory (":");
63 DirectoryInfo info = Directory.CreateDirectory (":");
64 DeleteDirectory (":");
67 [Test]
68 [ExpectedException(typeof(ArgumentNullException))]
69 public void CreateDirectoryArgumentNullException ()
71 DirectoryInfo info = Directory.CreateDirectory (null as string);
74 [Test]
75 [ExpectedException(typeof(ArgumentException))]
76 public void CreateDirectoryArgumentException1 ()
78 DirectoryInfo info = Directory.CreateDirectory ("");
81 [Test]
82 [ExpectedException(typeof(ArgumentException))]
83 public void CreateDirectoryArgumentException2 ()
85 DirectoryInfo info = Directory.CreateDirectory (" ");
88 [Test]
89 [ExpectedException(typeof(ArgumentException))]
90 public void CreateDirectoryArgumentException3 ()
92 string path = TempFolder + DSC + "DirectoryTest.Test";
93 DeleteDirectory (path);
94 try {
95 path += Path.InvalidPathChars [0];
96 path += ".2";
97 DirectoryInfo info = Directory.CreateDirectory (path);
98 } finally {
99 DeleteDirectory (path);
103 [Test]
104 public void Delete ()
106 string path = TempFolder + DSC + "DirectoryTest.Test.Delete.1";
107 DeleteDirectory (path);
108 try {
109 Directory.CreateDirectory (path);
110 AssertEquals ("test#01", true, Directory.Exists (path));
112 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
113 AssertEquals ("test#02", true, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
115 Directory.Delete (path + DSC + "DirectoryTest.Test.Delete.1.2");
116 AssertEquals ("test#03", false, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
117 AssertEquals ("test#04", true, Directory.Exists (path));
119 Directory.Delete (path);
120 AssertEquals ("test#05", false, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
121 AssertEquals ("test#06", false, Directory.Exists (path));
123 Directory.CreateDirectory (path);
124 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
125 AssertEquals ("test#07", true, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
126 AssertEquals ("test#08", true, Directory.Exists (path));
128 Directory.Delete (path, true);
129 AssertEquals ("test#09", false, Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"));
130 AssertEquals ("test#10", false, Directory.Exists (path));
131 } finally {
132 DeleteDirectory (path);
136 [Test]
137 [ExpectedException(typeof(ArgumentException))]
138 public void DeleteArgumentException ()
140 Directory.Delete ("");
143 [Test]
144 [ExpectedException(typeof(ArgumentException))]
145 public void DeleteArgumentException2 ()
147 Directory.Delete (" ");
150 [Test]
151 [ExpectedException(typeof(ArgumentException))]
152 public void DeleteArgumentException3 ()
154 string path = TempFolder + DSC + "DirectoryTest.Test.4";
155 DeleteDirectory (path);
157 path += Path.InvalidPathChars [0];
158 Directory.Delete (path);
161 [Test]
162 [ExpectedException(typeof(ArgumentNullException))]
163 public void DeleteArgumentNullException ()
165 Directory.Delete (null as string);
168 [Test]
169 [ExpectedException(typeof(DirectoryNotFoundException))]
170 public void DeleteDirectoryNotFoundException ()
172 string path = TempFolder + DSC + "DirectoryTest.Test.5";
173 DeleteDirectory (path);
175 Directory.Delete (path);
178 [Test]
179 [ExpectedException(typeof(IOException))]
180 public void DeleteArgumentException4 ()
182 string path = TempFolder + DSC + "DirectoryTest.Test.6";
183 DeleteDirectory (path);
184 FileStream s = null;
185 Directory.CreateDirectory (path);
186 try {
187 s = File.Create (path + DSC + "DirectoryTest.Test.6");
188 Directory.Delete (path);
189 } finally {
190 if (s != null)
191 s.Close ();
192 DeleteDirectory (path);
196 [Test]
197 public void Exists ()
199 AssertEquals ("test#01", false, Directory.Exists (null as string));
202 [Test]
203 [ExpectedException(typeof(ArgumentNullException))]
204 public void GetCreationTimeException1 ()
206 Directory.GetCreationTime (null as string);
209 [Test]
210 [ExpectedException(typeof(ArgumentException))]
211 public void GetCreationTimeException2 ()
213 Directory.GetCreationTime ("");
216 [Test]
217 [ExpectedException(typeof(IOException))]
218 public void GetCreationTimeException3 ()
220 string path = TempFolder + DSC + "DirectoryTest.GetCreationTime.1";
221 DeleteDirectory (path);
222 try {
223 Directory.GetCreationTime (path);
224 } finally {
225 DeleteDirectory (path);
229 [Test]
230 [ExpectedException(typeof(ArgumentException))]
231 public void GetCreationTimeException4 ()
233 Directory.GetCreationTime (" ");
236 [Test]
237 [ExpectedException(typeof(ArgumentException))]
238 public void GetCreationTimeException5 ()
240 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
243 [Test]
244 [ExpectedException(typeof(ArgumentNullException))]
245 public void GetCreationTimeUtcException1 ()
247 Directory.GetCreationTimeUtc (null as string);
250 [Test]
251 [ExpectedException(typeof(ArgumentException))]
252 public void GetCreationTimeUtcException2 ()
254 Directory.GetCreationTimeUtc ("");
257 [Test]
258 [ExpectedException(typeof(IOException))]
259 public void GetCreationTimeUtcException3 ()
261 string path = TempFolder + DSC + "DirectoryTest.GetCreationTimeUtc.1";
262 DeleteDirectory (path);
264 try {
265 Directory.GetCreationTimeUtc (path);
266 } finally {
267 DeleteDirectory (path);
271 [Test]
272 [ExpectedException(typeof(ArgumentException))]
273 public void GetCreationTimeUtcException4 ()
275 Directory.GetCreationTimeUtc (" ");
278 [Test]
279 [ExpectedException(typeof(ArgumentException))]
280 public void GetCreationTimeUtcException5 ()
282 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
285 [Test]
286 [ExpectedException(typeof(ArgumentNullException))]
287 public void GetLastAccessTimeException1 ()
289 Directory.GetLastAccessTime (null as string);
292 [Test]
293 [ExpectedException(typeof(ArgumentException))]
294 public void GetLastAccessTimeException2 ()
296 Directory.GetLastAccessTime ("");
299 [Test]
300 [ExpectedException(typeof(IOException))]
301 public void GetLastAccessTimeException3 ()
303 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTime.1";
304 DeleteDirectory (path);
306 try {
307 Directory.GetLastAccessTime (path);
308 } finally {
309 DeleteDirectory (path);
313 [Test]
314 [ExpectedException(typeof(ArgumentException))]
315 public void GetLastAccessTimeException4 ()
317 Directory.GetLastAccessTime (" ");
320 [Test]
321 [ExpectedException(typeof(ArgumentException))]
322 public void GetLastAccessTimeException5 ()
324 Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
327 [Test]
328 [ExpectedException(typeof(ArgumentNullException))]
329 public void GetLastAccessTimeUtcException1 ()
331 Directory.GetLastAccessTimeUtc (null as string);
334 [Test]
335 [ExpectedException(typeof(ArgumentException))]
336 public void GetLastAccessTimeUtcException2 ()
338 Directory.GetLastAccessTimeUtc ("");
341 [Test]
342 [ExpectedException(typeof(IOException))]
343 public void GetLastAccessTimeUtcException3 ()
345 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTimeUtc.1";
346 DeleteDirectory (path);
347 try {
348 Directory.GetLastAccessTimeUtc (path);
349 } finally {
350 DeleteDirectory (path);
354 [Test]
355 [ExpectedException(typeof(ArgumentException))]
356 public void GetLastAccessTimeUtcException4 ()
358 Directory.GetLastAccessTimeUtc (" ");
361 [Test]
362 [ExpectedException(typeof(ArgumentException))]
363 public void GetLastAccessTimeUtcException5 ()
365 Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
368 [Test]
369 [ExpectedException(typeof(ArgumentNullException))]
370 public void GetLastWriteTimeException1 ()
372 Directory.GetLastWriteTime (null as string);
375 [Test]
376 [ExpectedException(typeof(ArgumentException))]
377 public void GetLastWriteTimeException2 ()
379 Directory.GetLastWriteTime ("");
382 [Test]
383 [ExpectedException(typeof(IOException))]
384 public void GetLastWriteTimeException3 ()
386 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTime.1";
387 DeleteDirectory (path);
388 try {
389 Directory.GetLastWriteTime (path);
390 } finally {
391 DeleteDirectory (path);
395 [Test]
396 [ExpectedException(typeof(ArgumentException))]
397 public void GetLastWriteTimeException4 ()
399 Directory.GetLastWriteTime (" ");
402 [Test]
403 [ExpectedException(typeof(ArgumentException))]
404 public void GetLastWriteTimeException5 ()
406 Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
409 [Test]
410 [ExpectedException(typeof(ArgumentNullException))]
411 public void GetLastWriteTimeUtcException1 ()
413 Directory.GetLastWriteTimeUtc (null as string);
416 [Test]
417 [ExpectedException(typeof(ArgumentException))]
418 public void GetLastWriteTimeUtcException2 ()
420 Directory.GetLastAccessTimeUtc ("");
423 [Test]
424 [ExpectedException(typeof(IOException))]
425 public void GetLastWriteTimeUtcException3 ()
427 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTimeUtc.1";
428 DeleteDirectory (path);
429 try {
430 Directory.GetLastAccessTimeUtc (path);
431 } finally {
432 DeleteDirectory (path);
437 [Test]
438 [ExpectedException(typeof(ArgumentException))]
439 public void GetLastWriteTimeUtcException4 ()
441 Directory.GetLastAccessTimeUtc (" ");
444 [Test]
445 [ExpectedException(typeof(ArgumentException))]
446 public void GetLastWriteTimeUtcException5 ()
448 Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
451 [Test]
452 public void Move ()
454 string path = TempFolder + DSC + "DirectoryTest.Test.9";
455 string path2 = TempFolder + DSC + "DirectoryTest.Test.10";
456 DeleteDirectory (path);
457 DeleteDirectory (path2);
458 try {
459 Directory.CreateDirectory (path);
460 Directory.CreateDirectory (path + DSC + "dir");
461 AssertEquals ("test#01", true, Directory.Exists (path + DSC + "dir"));
463 Directory.Move (path, path2);
464 AssertEquals ("test#02", false, Directory.Exists (path + DSC + "dir"));
465 AssertEquals ("test#03", true, Directory.Exists (path2 + DSC + "dir"));
467 } finally {
468 DeleteDirectory (path);
469 DeleteDirectory (path2);
470 if (Directory.Exists (path2 + DSC + "dir"))
471 Directory.Delete (path2 + DSC + "dir", true);
475 [Test]
476 [ExpectedException(typeof(IOException))]
477 public void MoveException1 ()
479 string path = TempFolder + DSC + "DirectoryTest.Test.8";
480 DeleteDirectory (path);
481 try {
482 Directory.Move (path, path);
483 } finally {
484 DeleteDirectory (path);
488 [Test]
489 [ExpectedException(typeof(ArgumentException))]
490 public void MoveException2 ()
492 string path = TempFolder + DSC + "DirectoryTest.Test.11";
493 DeleteDirectory (path);
494 try {
495 Directory.Move ("", path);
496 } finally {
497 DeleteDirectory (path);
501 [Test]
502 [ExpectedException(typeof(ArgumentException))]
503 public void MoveException3 ()
505 string path = TempFolder + DSC + "DirectoryTest.Test.12";
506 DeleteDirectory (path);
507 try {
508 Directory.Move (" ", path);
509 } finally {
510 DeleteDirectory (path);
514 [Test]
515 [ExpectedException(typeof(ArgumentException))]
516 public void MoveException4 ()
518 string path = TempFolder + DSC + "DirectoryTest.Test.13";
519 path += Path.InvalidPathChars [0];
520 string path2 = TempFolder + DSC + "DirectoryTest.Test.13";
521 DeleteDirectory (path);
522 DeleteDirectory (path2);
523 try {
524 Directory.CreateDirectory (path2);
525 Directory.Move (path2, path);
526 } finally {
527 DeleteDirectory (path);
528 DeleteDirectory (path2);
532 [Test]
533 [ExpectedException(typeof(DirectoryNotFoundException))]
534 public void MoveException5 ()
536 string path = TempFolder + DSC + "DirectoryTest.Test.14";
537 DeleteDirectory (path);
538 try {
539 Directory.Move (path, path + "Test.Test");
540 } finally {
541 DeleteDirectory (path);
542 DeleteDirectory (path + "Test.Test");
546 [Test]
547 [ExpectedException(typeof(IOException))]
548 public void MoveException6 ()
550 string path = TempFolder + DSC + "DirectoryTest.Test.15";
551 DeleteDirectory (path);
552 try {
553 Directory.CreateDirectory (path);
554 Directory.Move (path, path + DSC + "dir");
555 } finally {
556 DeleteDirectory (path);
557 DeleteDirectory (path + DSC + "dir");
561 [Test]
562 [ExpectedException(typeof(IOException))]
563 public void MoveException7 ()
565 string path = TempFolder + DSC + "DirectoryTest.Test.16";
566 string path2 = TempFolder + DSC + "DirectoryTest.Test.17";
568 DeleteDirectory (path);
569 DeleteDirectory (path2);
570 try {
571 Directory.CreateDirectory (path);
572 Directory.CreateDirectory (path2);
573 Directory.Move (path, path2);
574 } finally {
575 DeleteDirectory (path);
576 DeleteDirectory (path2);
580 [Test]
581 [Ignore("Unix doesnt support CreationTime")]
582 public void CreationTime ()
584 string path = TempFolder + DSC + "DirectoryTest.CreationTime.1";
585 DeleteDirectory (path);
587 try {
588 Directory.CreateDirectory (path);
589 Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
591 DateTime time = Directory.GetCreationTime (path);
592 AssertEquals ("test#01", 2003, time.Year);
593 AssertEquals ("test#02", 6, time.Month);
594 AssertEquals ("test#03", 4, time.Day);
595 AssertEquals ("test#04", 6, time.Hour);
596 AssertEquals ("test#05", 4, time.Minute);
597 AssertEquals ("test#06", 0, time.Second);
599 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
600 AssertEquals ("test#07", 2003, time.Year);
601 AssertEquals ("test#08", 6, time.Month);
602 AssertEquals ("test#09", 4, time.Day);
603 AssertEquals ("test#10", 6, time.Hour);
604 AssertEquals ("test#11", 4, time.Minute);
605 AssertEquals ("test#12", 0, time.Second);
607 Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
608 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
609 AssertEquals ("test#13", 2003, time.Year);
610 AssertEquals ("test#14", 6, time.Month);
611 AssertEquals ("test#15", 4, time.Day);
612 AssertEquals ("test#16", 6, time.Hour);
613 AssertEquals ("test#17", 4, time.Minute);
614 AssertEquals ("test#18", 0, time.Second);
616 time = Directory.GetCreationTimeUtc (path);
617 AssertEquals ("test#19", 2003, time.Year);
618 AssertEquals ("test#20", 6, time.Month);
619 AssertEquals ("test#21", 4, time.Day);
620 AssertEquals ("test#22", 6, time.Hour);
621 AssertEquals ("test#23", 4, time.Minute);
622 AssertEquals ("test#24", 0, time.Second);
623 } finally {
624 DeleteDirectory (path);
628 [Test]
629 public void LastAccessTime ()
631 string path = TempFolder + DSC + "DirectoryTest.AccessTime.1";
632 DeleteDirectory (path);
634 try {
635 Directory.CreateDirectory (path);
636 Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
638 DateTime time = Directory.GetLastAccessTime (path);
639 AssertEquals ("test#01", 2003, time.Year);
640 AssertEquals ("test#02", 6, time.Month);
641 AssertEquals ("test#03", 4, time.Day);
642 AssertEquals ("test#04", 6, time.Hour);
643 AssertEquals ("test#05", 4, time.Minute);
644 AssertEquals ("test#06", 0, time.Second);
646 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
647 AssertEquals ("test#07", 2003, time.Year);
648 AssertEquals ("test#08", 6, time.Month);
649 AssertEquals ("test#09", 4, time.Day);
650 AssertEquals ("test#10", 6, time.Hour);
651 AssertEquals ("test#11", 4, time.Minute);
652 AssertEquals ("test#12", 0, time.Second);
654 Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
655 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
656 AssertEquals ("test#13", 2003, time.Year);
657 AssertEquals ("test#14", 6, time.Month);
658 AssertEquals ("test#15", 4, time.Day);
659 AssertEquals ("test#16", 6, time.Hour);
660 AssertEquals ("test#17", 4, time.Minute);
661 AssertEquals ("test#18", 0, time.Second);
663 time = Directory.GetLastAccessTimeUtc (path);
664 AssertEquals ("test#19", 2003, time.Year);
665 AssertEquals ("test#20", 6, time.Month);
666 AssertEquals ("test#21", 4, time.Day);
667 AssertEquals ("test#22", 6, time.Hour);
668 AssertEquals ("test#23", 4, time.Minute);
669 AssertEquals ("test#24", 0, time.Second);
670 } finally {
671 DeleteDirectory (path);
675 [Test]
676 public void LastWriteTime ()
678 string path = TempFolder + DSC + "DirectoryTest.WriteTime.1";
679 DeleteDirectory (path);
681 try {
682 Directory.CreateDirectory (path);
683 Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
685 DateTime time = Directory.GetLastWriteTime (path);
686 AssertEquals ("test#01", 2003, time.Year);
687 AssertEquals ("test#02", 6, time.Month);
688 AssertEquals ("test#03", 4, time.Day);
689 AssertEquals ("test#04", 6, time.Hour);
690 AssertEquals ("test#05", 4, time.Minute);
691 AssertEquals ("test#06", 0, time.Second);
693 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
694 AssertEquals ("test#07", 2003, time.Year);
695 AssertEquals ("test#08", 6, time.Month);
696 AssertEquals ("test#09", 4, time.Day);
697 AssertEquals ("test#10", 6, time.Hour);
698 AssertEquals ("test#11", 4, time.Minute);
699 AssertEquals ("test#12", 0, time.Second);
701 Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
702 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
703 AssertEquals ("test#13", 2003, time.Year);
704 AssertEquals ("test#14", 6, time.Month);
705 AssertEquals ("test#15", 4, time.Day);
706 AssertEquals ("test#16", 6, time.Hour);
707 AssertEquals ("test#17", 4, time.Minute);
708 AssertEquals ("test#18", 0, time.Second);
710 time = Directory.GetLastWriteTimeUtc (path);
711 AssertEquals ("test#19", 2003, time.Year);
712 AssertEquals ("test#20", 6, time.Month);
713 AssertEquals ("test#21", 4, time.Day);
714 AssertEquals ("test#22", 6, time.Hour);
715 AssertEquals ("test#23", 4, time.Minute);
716 AssertEquals ("test#24", 0, time.Second);
717 } finally {
718 DeleteDirectory (path);
722 [Test]
723 [ExpectedException(typeof(ArgumentNullException))]
724 public void SetLastWriteTimeException1 ()
726 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
727 Directory.SetLastWriteTime (null as string, time);
730 [Test]
731 [ExpectedException(typeof(ArgumentException))]
732 public void SetLastWriteTimeException2 ()
734 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
735 Directory.SetLastWriteTime ("", time);
738 [Test]
739 [ExpectedException(typeof(FileNotFoundException))]
740 public void SetLastWriteTimeException3 ()
742 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
743 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTime.2";
744 DeleteDirectory (path);
745 try {
746 Directory.SetLastWriteTime (path, time);
747 } finally {
748 DeleteDirectory (path);
752 [Test]
753 [ExpectedException(typeof(ArgumentException))]
754 public void SetLastWriteTimeException4 ()
756 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
757 Directory.SetLastWriteTime (" ", time);
760 [Test]
761 [ExpectedException(typeof(ArgumentException))]
762 public void SetLastWriteTimeException5 ()
764 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
765 Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
768 // [Test]
769 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
770 // public void SetLastWriteTimeException6 ()
771 // {
772 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
773 // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
775 // try {
776 // if (!Directory.Exists (path))
777 // Directory.CreateDirectory (path);
779 // Directory.SetLastWriteTime (path, time);
780 // } finally {
781 // DeleteDirectory (path);
782 // }
784 // }
786 [Test]
787 [ExpectedException(typeof(ArgumentNullException))]
788 public void SetLastWriteTimeUtcException1 ()
790 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
791 Directory.SetLastWriteTimeUtc (null as string, time);
794 [Test]
795 [ExpectedException(typeof(ArgumentException))]
796 public void SetLastWriteTimeUtcException2 ()
798 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
799 Directory.SetLastWriteTimeUtc ("", time);
802 [Test]
803 [ExpectedException(typeof(FileNotFoundException))]
804 public void SetLastWriteTimeUtcException3 ()
806 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
807 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.2";
808 DeleteDirectory (path);
809 try {
810 Directory.SetLastWriteTimeUtc (path, time);
811 } finally {
812 DeleteDirectory (path);
816 [Test]
817 [ExpectedException(typeof(ArgumentException))]
818 public void SetLastWriteTimeUtcException4 ()
820 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
821 Directory.SetLastWriteTimeUtc (" ", time);
824 [Test]
825 [ExpectedException(typeof(ArgumentException))]
826 public void SetLastWriteTimeUtcException5 ()
828 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
829 Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
832 // [Test]
833 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
834 // public void SetLastWriteTimeUtcException6 ()
835 // {
836 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
837 // string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.1";
839 // if (!Directory.Exists (path))
840 // Directory.CreateDirectory (path);
841 // try {
842 // Directory.SetLastWriteTimeUtc (path, time);
843 // } finally {
844 // DeleteDirectory (path);
845 // }
846 // }
848 [Test]
849 [ExpectedException(typeof(ArgumentNullException))]
850 public void SetLastAccessTimeException1 ()
852 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
853 Directory.SetLastAccessTime (null as string, time);
856 [Test]
857 [ExpectedException(typeof(ArgumentException))]
858 public void SetLastAccessTimeException2 ()
860 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
861 Directory.SetLastAccessTime ("", time);
864 [Test]
865 [ExpectedException(typeof(FileNotFoundException))]
866 public void SetLastAccessTimeException3 ()
868 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
869 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.2";
870 DeleteDirectory (path);
871 try {
872 Directory.SetLastAccessTime (path, time);
873 } finally {
874 DeleteDirectory (path);
878 [Test]
879 [ExpectedException(typeof(ArgumentException))]
880 public void SetLastAccessTimeException4 ()
882 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
883 Directory.SetLastAccessTime (" ", time);
886 [Test]
887 [ExpectedException(typeof(ArgumentException))]
888 public void SetLastAccessTimeException5 ()
890 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
891 Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
894 // [Test]
895 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
896 // public void SetLastAccessTimeException6 ()
897 // {
898 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
899 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.1";
901 // if (!Directory.Exists (path))
902 // Directory.CreateDirectory (path);
903 // try {
904 // Directory.SetLastAccessTime (path, time);
905 // } finally {
906 // DeleteDirectory (path);
907 // }
909 // }
911 [Test]
912 [ExpectedException(typeof(ArgumentNullException))]
913 public void SetLastAccessTimeUtcException1 ()
915 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
916 Directory.SetLastAccessTimeUtc (null as string, time);
919 [Test]
920 [ExpectedException(typeof(ArgumentException))]
921 public void SetLastAccessTimeUtcException2 ()
923 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
924 Directory.SetLastAccessTimeUtc ("", time);
927 [Test]
928 [ExpectedException(typeof(FileNotFoundException))]
929 public void SetLastAccessTimeUtcException3 ()
931 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
932 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
933 DeleteDirectory (path);
934 try {
935 Directory.SetLastAccessTimeUtc (path, time);
936 } finally {
937 DeleteDirectory (path);
941 [Test]
942 [ExpectedException(typeof(ArgumentException))]
943 public void SetLastAccessTimeUtcException4 ()
945 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
946 Directory.SetLastAccessTimeUtc (" ", time);
949 [Test]
950 [ExpectedException(typeof(ArgumentException))]
951 public void SetLastAccessTimeUtcException5 ()
953 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
954 Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
957 // [Test]
958 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
959 // public void SetLastAccessTimeUtcException6 ()
960 // {
961 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
962 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
964 // if (!Directory.Exists (path))
965 // Directory.CreateDirectory (path);
966 // try {
967 // Directory.SetLastAccessTimeUtc (path, time);
968 // } finally {
969 // DeleteDirectory (path);
970 // }
971 // }
973 [ExpectedException(typeof(ArgumentNullException))]
974 public void SetCreationTimeException1 ()
976 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
977 Directory.SetCreationTime (null as string, time);
980 [Test]
981 [ExpectedException(typeof(ArgumentException))]
982 public void SetCreationTimeException2 ()
984 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
985 Directory.SetCreationTime ("", time);
988 [Test]
989 [ExpectedException(typeof(FileNotFoundException))]
990 public void SetCreationTimeException3 ()
992 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
993 string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.2";
994 DeleteDirectory (path);
996 try {
997 Directory.SetCreationTime (path, time);
998 } finally {
999 DeleteDirectory (path);
1003 [Test]
1004 [ExpectedException(typeof(ArgumentException))]
1005 public void SetCreationTimeException4 ()
1007 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1008 Directory.SetCreationTime (" ", time);
1011 [Test]
1012 [ExpectedException(typeof(ArgumentException))]
1013 public void SetCreationTimeException5 ()
1015 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1016 Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
1019 // [Test]
1020 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
1021 // public void SetCreationTimeException6 ()
1022 // {
1023 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
1024 // string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.1";
1026 // if (!Directory.Exists (path))
1027 // Directory.CreateDirectory (path);
1028 // try {
1029 // Directory.SetCreationTime (path, time);
1030 // DeleteDirectory (path);
1031 // } finally {
1032 // DeleteDirectory (path);
1033 // }
1035 // }
1037 [Test]
1038 [ExpectedException(typeof(ArgumentNullException))]
1039 public void SetCreationTimeUtcException1 ()
1041 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1042 Directory.SetCreationTimeUtc (null as string, time);
1045 [Test]
1046 [ExpectedException(typeof(ArgumentException))]
1047 public void SetCreationTimeUtcException2 ()
1049 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1050 Directory.SetCreationTimeUtc ("", time);
1053 [Test]
1054 [ExpectedException(typeof(FileNotFoundException))]
1055 public void SetCreationTimeUtcException3 ()
1057 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1058 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
1059 DeleteDirectory (path);
1061 try {
1062 Directory.SetCreationTimeUtc (path, time);
1063 DeleteDirectory (path);
1064 } finally {
1065 DeleteDirectory (path);
1069 [Test]
1070 [ExpectedException(typeof(ArgumentException))]
1071 public void SetCreationTimeUtcException4 ()
1073 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1074 Directory.SetCreationTimeUtc (" ", time);
1077 [Test]
1078 [ExpectedException(typeof(ArgumentException))]
1079 public void SetCreationTimeUtcException5 ()
1081 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
1082 Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
1085 // [Test]
1086 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
1087 // public void SetCreationTimeUtcException6 ()
1088 // {
1089 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
1090 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
1092 // if (!Directory.Exists (path))
1093 // Directory.CreateDirectory (path);
1094 // try {
1095 // Directory.SetCreationTimeUtc (path, time);
1096 // DeleteDirectory (path);
1097 // } finally {
1098 // DeleteDirectory (path);
1099 // }
1100 // }
1102 [Test]
1103 public void GetDirectories ()
1105 string path = TempFolder;
1106 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetDirectories";
1107 DeleteDirectory (DirPath);
1109 try {
1110 Directory.CreateDirectory (DirPath);
1112 string [] dirs = Directory.GetDirectories (path);
1114 foreach (string directory in dirs) {
1116 if (directory == DirPath)
1117 return;
1120 Assert ("Directory Not Found", false);
1121 } finally {
1122 DeleteDirectory (DirPath);
1126 [Test]
1127 public void GetParentOfRootDirectory ()
1129 DirectoryInfo info;
1131 info = Directory.GetParent (Path.GetPathRoot (Path.GetTempPath ()));
1132 AssertEquals (null, info);
1135 [Test]
1136 public void GetFiles ()
1138 string path = TempFolder;
1139 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetFiles";
1140 if (File.Exists (DirPath))
1141 File.Delete (DirPath);
1143 try {
1144 File.Create (DirPath).Close ();
1145 string [] files = Directory.GetFiles (TempFolder);
1146 foreach (string directory in files) {
1148 if (directory == DirPath)
1149 return;
1152 Assert ("File Not Found", false);
1153 } finally {
1154 if (File.Exists (DirPath))
1155 File.Delete (DirPath);
1160 [Test]
1161 [ExpectedException (typeof (ArgumentNullException))]
1162 public void SetCurrentDirectoryNull ()
1164 Directory.SetCurrentDirectory (null);
1167 [Test]
1168 [ExpectedException (typeof (ArgumentException))]
1169 public void SetCurrentDirectoryEmpty ()
1171 Directory.SetCurrentDirectory (String.Empty);
1174 [Test]
1175 [ExpectedException (typeof (ArgumentException))]
1176 public void SetCurrentDirectoryWhitespace ()
1178 Directory.SetCurrentDirectory (" ");
1182 [Test]
1183 public void GetNoFiles () // Bug 58875. This throwed an exception on windows.
1185 DirectoryInfo dir = new DirectoryInfo (".");
1186 dir.GetFiles ("*.nonext");
1189 private void DeleteDirectory (string path)
1191 if (Directory.Exists (path))
1192 Directory.Delete (path, true);