5 // Ville Palo (vi64pa@kolumbus.fi)
9 // TODO: Find out why ArgumentOutOfRange tests does not release directories properly
12 using NUnit
.Framework
;
16 using System
.Globalization
;
17 using System
.Threading
;
19 namespace MonoTests
.System
.IO
{
22 public class DirectoryTest
: Assertion
{
24 string TempFolder
= Path
.Combine (Path
.GetTempPath (), "MonoTests.System.IO.Tests");
25 static readonly char DSC
= Path
.DirectorySeparatorChar
;
30 if (!Directory
.Exists (TempFolder
))
31 Directory
.CreateDirectory (TempFolder
);
33 Thread
.CurrentThread
.CurrentCulture
= new CultureInfo ("en-US");
37 public void TearDown () {
38 if (Directory
.Exists (TempFolder
))
39 Directory
.Delete (TempFolder
, true);
43 public void CreateDirectory ()
45 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.1";
46 DeleteDirectory (path
);
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
);
54 DeleteDirectory (path
);
59 [ExpectedException(typeof(ArgumentException
))]
60 public void CreateDirectoryNotSupportedException ()
62 DeleteDirectory (":");
63 DirectoryInfo info
= Directory
.CreateDirectory (":");
64 DeleteDirectory (":");
68 [ExpectedException(typeof(ArgumentNullException
))]
69 public void CreateDirectoryArgumentNullException ()
71 DirectoryInfo info
= Directory
.CreateDirectory (null as string);
75 [ExpectedException(typeof(ArgumentException
))]
76 public void CreateDirectoryArgumentException1 ()
78 DirectoryInfo info
= Directory
.CreateDirectory ("");
82 [ExpectedException(typeof(ArgumentException
))]
83 public void CreateDirectoryArgumentException2 ()
85 DirectoryInfo info
= Directory
.CreateDirectory (" ");
89 [ExpectedException(typeof(ArgumentException
))]
90 public void CreateDirectoryArgumentException3 ()
92 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test";
93 DeleteDirectory (path
);
95 path
+= Path
.InvalidPathChars
[0];
97 DirectoryInfo info
= Directory
.CreateDirectory (path
);
99 DeleteDirectory (path
);
104 public void Delete ()
106 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.Delete.1";
107 DeleteDirectory (path
);
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
));
132 DeleteDirectory (path
);
137 [ExpectedException(typeof(ArgumentException
))]
138 public void DeleteArgumentException ()
140 Directory
.Delete ("");
144 [ExpectedException(typeof(ArgumentException
))]
145 public void DeleteArgumentException2 ()
147 Directory
.Delete (" ");
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
);
162 [ExpectedException(typeof(ArgumentNullException
))]
163 public void DeleteArgumentNullException ()
165 Directory
.Delete (null as string);
169 [ExpectedException(typeof(DirectoryNotFoundException
))]
170 public void DeleteDirectoryNotFoundException ()
172 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.5";
173 DeleteDirectory (path
);
175 Directory
.Delete (path
);
179 [ExpectedException(typeof(IOException
))]
180 public void DeleteArgumentException4 ()
182 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.6";
183 DeleteDirectory (path
);
185 Directory
.CreateDirectory (path
);
187 s
= File
.Create (path
+ DSC
+ "DirectoryTest.Test.6");
188 Directory
.Delete (path
);
192 DeleteDirectory (path
);
197 public void Exists ()
199 AssertEquals ("test#01", false, Directory
.Exists (null as string));
203 [ExpectedException(typeof(ArgumentNullException
))]
204 public void GetCreationTimeException1 ()
206 Directory
.GetCreationTime (null as string);
210 [ExpectedException(typeof(ArgumentException
))]
211 public void GetCreationTimeException2 ()
213 Directory
.GetCreationTime ("");
217 [ExpectedException(typeof(IOException
))]
218 public void GetCreationTimeException3 ()
220 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetCreationTime.1";
221 DeleteDirectory (path
);
223 Directory
.GetCreationTime (path
);
225 DeleteDirectory (path
);
230 [ExpectedException(typeof(ArgumentException
))]
231 public void GetCreationTimeException4 ()
233 Directory
.GetCreationTime (" ");
237 [ExpectedException(typeof(ArgumentException
))]
238 public void GetCreationTimeException5 ()
240 Directory
.GetCreationTime (Path
.InvalidPathChars
[0].ToString ());
244 [ExpectedException(typeof(ArgumentNullException
))]
245 public void GetCreationTimeUtcException1 ()
247 Directory
.GetCreationTimeUtc (null as string);
251 [ExpectedException(typeof(ArgumentException
))]
252 public void GetCreationTimeUtcException2 ()
254 Directory
.GetCreationTimeUtc ("");
258 [ExpectedException(typeof(IOException
))]
259 public void GetCreationTimeUtcException3 ()
261 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetCreationTimeUtc.1";
262 DeleteDirectory (path
);
265 Directory
.GetCreationTimeUtc (path
);
267 DeleteDirectory (path
);
272 [ExpectedException(typeof(ArgumentException
))]
273 public void GetCreationTimeUtcException4 ()
275 Directory
.GetCreationTimeUtc (" ");
279 [ExpectedException(typeof(ArgumentException
))]
280 public void GetCreationTimeUtcException5 ()
282 Directory
.GetCreationTime (Path
.InvalidPathChars
[0].ToString ());
286 [ExpectedException(typeof(ArgumentNullException
))]
287 public void GetLastAccessTimeException1 ()
289 Directory
.GetLastAccessTime (null as string);
293 [ExpectedException(typeof(ArgumentException
))]
294 public void GetLastAccessTimeException2 ()
296 Directory
.GetLastAccessTime ("");
300 [ExpectedException(typeof(IOException
))]
301 public void GetLastAccessTimeException3 ()
303 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetLastAccessTime.1";
304 DeleteDirectory (path
);
307 Directory
.GetLastAccessTime (path
);
309 DeleteDirectory (path
);
314 [ExpectedException(typeof(ArgumentException
))]
315 public void GetLastAccessTimeException4 ()
317 Directory
.GetLastAccessTime (" ");
321 [ExpectedException(typeof(ArgumentException
))]
322 public void GetLastAccessTimeException5 ()
324 Directory
.GetLastAccessTime (Path
.InvalidPathChars
[0].ToString ());
328 [ExpectedException(typeof(ArgumentNullException
))]
329 public void GetLastAccessTimeUtcException1 ()
331 Directory
.GetLastAccessTimeUtc (null as string);
335 [ExpectedException(typeof(ArgumentException
))]
336 public void GetLastAccessTimeUtcException2 ()
338 Directory
.GetLastAccessTimeUtc ("");
342 [ExpectedException(typeof(IOException
))]
343 public void GetLastAccessTimeUtcException3 ()
345 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetLastAccessTimeUtc.1";
346 DeleteDirectory (path
);
348 Directory
.GetLastAccessTimeUtc (path
);
350 DeleteDirectory (path
);
355 [ExpectedException(typeof(ArgumentException
))]
356 public void GetLastAccessTimeUtcException4 ()
358 Directory
.GetLastAccessTimeUtc (" ");
362 [ExpectedException(typeof(ArgumentException
))]
363 public void GetLastAccessTimeUtcException5 ()
365 Directory
.GetLastAccessTimeUtc (Path
.InvalidPathChars
[0].ToString ());
369 [ExpectedException(typeof(ArgumentNullException
))]
370 public void GetLastWriteTimeException1 ()
372 Directory
.GetLastWriteTime (null as string);
376 [ExpectedException(typeof(ArgumentException
))]
377 public void GetLastWriteTimeException2 ()
379 Directory
.GetLastWriteTime ("");
383 [ExpectedException(typeof(IOException
))]
384 public void GetLastWriteTimeException3 ()
386 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetLastWriteTime.1";
387 DeleteDirectory (path
);
389 Directory
.GetLastWriteTime (path
);
391 DeleteDirectory (path
);
396 [ExpectedException(typeof(ArgumentException
))]
397 public void GetLastWriteTimeException4 ()
399 Directory
.GetLastWriteTime (" ");
403 [ExpectedException(typeof(ArgumentException
))]
404 public void GetLastWriteTimeException5 ()
406 Directory
.GetLastWriteTime (Path
.InvalidPathChars
[0].ToString ());
410 [ExpectedException(typeof(ArgumentNullException
))]
411 public void GetLastWriteTimeUtcException1 ()
413 Directory
.GetLastWriteTimeUtc (null as string);
417 [ExpectedException(typeof(ArgumentException
))]
418 public void GetLastWriteTimeUtcException2 ()
420 Directory
.GetLastAccessTimeUtc ("");
424 [ExpectedException(typeof(IOException
))]
425 public void GetLastWriteTimeUtcException3 ()
427 string path
= TempFolder
+ DSC
+ "DirectoryTest.GetLastWriteTimeUtc.1";
428 DeleteDirectory (path
);
430 Directory
.GetLastAccessTimeUtc (path
);
432 DeleteDirectory (path
);
438 [ExpectedException(typeof(ArgumentException
))]
439 public void GetLastWriteTimeUtcException4 ()
441 Directory
.GetLastAccessTimeUtc (" ");
445 [ExpectedException(typeof(ArgumentException
))]
446 public void GetLastWriteTimeUtcException5 ()
448 Directory
.GetLastAccessTimeUtc (Path
.InvalidPathChars
[0].ToString ());
454 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.9";
455 string path2
= TempFolder
+ DSC
+ "DirectoryTest.Test.10";
456 DeleteDirectory (path
);
457 DeleteDirectory (path2
);
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"));
468 DeleteDirectory (path
);
469 DeleteDirectory (path2
);
470 if (Directory
.Exists (path2
+ DSC
+ "dir"))
471 Directory
.Delete (path2
+ DSC
+ "dir", true);
476 [ExpectedException(typeof(IOException
))]
477 public void MoveException1 ()
479 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.8";
480 DeleteDirectory (path
);
482 Directory
.Move (path
, path
);
484 DeleteDirectory (path
);
489 [ExpectedException(typeof(ArgumentException
))]
490 public void MoveException2 ()
492 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.11";
493 DeleteDirectory (path
);
495 Directory
.Move ("", path
);
497 DeleteDirectory (path
);
502 [ExpectedException(typeof(ArgumentException
))]
503 public void MoveException3 ()
505 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.12";
506 DeleteDirectory (path
);
508 Directory
.Move (" ", path
);
510 DeleteDirectory (path
);
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
);
524 Directory
.CreateDirectory (path2
);
525 Directory
.Move (path2
, path
);
527 DeleteDirectory (path
);
528 DeleteDirectory (path2
);
533 [ExpectedException(typeof(DirectoryNotFoundException
))]
534 public void MoveException5 ()
536 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.14";
537 DeleteDirectory (path
);
539 Directory
.Move (path
, path
+ "Test.Test");
541 DeleteDirectory (path
);
542 DeleteDirectory (path
+ "Test.Test");
547 [ExpectedException(typeof(IOException
))]
548 public void MoveException6 ()
550 string path
= TempFolder
+ DSC
+ "DirectoryTest.Test.15";
551 DeleteDirectory (path
);
553 Directory
.CreateDirectory (path
);
554 Directory
.Move (path
, path
+ DSC
+ "dir");
556 DeleteDirectory (path
);
557 DeleteDirectory (path
+ DSC
+ "dir");
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
);
571 Directory
.CreateDirectory (path
);
572 Directory
.CreateDirectory (path2
);
573 Directory
.Move (path
, path2
);
575 DeleteDirectory (path
);
576 DeleteDirectory (path2
);
581 [Ignore("Unix doesnt support CreationTime")]
582 public void CreationTime ()
584 string path
= TempFolder
+ DSC
+ "DirectoryTest.CreationTime.1";
585 DeleteDirectory (path
);
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
);
624 DeleteDirectory (path
);
629 public void LastAccessTime ()
631 string path
= TempFolder
+ DSC
+ "DirectoryTest.AccessTime.1";
632 DeleteDirectory (path
);
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
);
671 DeleteDirectory (path
);
676 public void LastWriteTime ()
678 string path
= TempFolder
+ DSC
+ "DirectoryTest.WriteTime.1";
679 DeleteDirectory (path
);
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
);
718 DeleteDirectory (path
);
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
);
731 [ExpectedException(typeof(ArgumentException
))]
732 public void SetLastWriteTimeException2 ()
734 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
735 Directory
.SetLastWriteTime ("", time
);
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
);
746 Directory
.SetLastWriteTime (path
, time
);
748 DeleteDirectory (path
);
753 [ExpectedException(typeof(ArgumentException
))]
754 public void SetLastWriteTimeException4 ()
756 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
757 Directory
.SetLastWriteTime (" ", time
);
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
);
769 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
770 // public void SetLastWriteTimeException6 ()
772 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
773 // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
776 // if (!Directory.Exists (path))
777 // Directory.CreateDirectory (path);
779 // Directory.SetLastWriteTime (path, time);
781 // DeleteDirectory (path);
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
);
795 [ExpectedException(typeof(ArgumentException
))]
796 public void SetLastWriteTimeUtcException2 ()
798 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
799 Directory
.SetLastWriteTimeUtc ("", time
);
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
);
810 Directory
.SetLastWriteTimeUtc (path
, time
);
812 DeleteDirectory (path
);
817 [ExpectedException(typeof(ArgumentException
))]
818 public void SetLastWriteTimeUtcException4 ()
820 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
821 Directory
.SetLastWriteTimeUtc (" ", time
);
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
);
833 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
834 // public void SetLastWriteTimeUtcException6 ()
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);
842 // Directory.SetLastWriteTimeUtc (path, time);
844 // DeleteDirectory (path);
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
);
857 [ExpectedException(typeof(ArgumentException
))]
858 public void SetLastAccessTimeException2 ()
860 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
861 Directory
.SetLastAccessTime ("", time
);
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
);
872 Directory
.SetLastAccessTime (path
, time
);
874 DeleteDirectory (path
);
879 [ExpectedException(typeof(ArgumentException
))]
880 public void SetLastAccessTimeException4 ()
882 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
883 Directory
.SetLastAccessTime (" ", time
);
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
);
895 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
896 // public void SetLastAccessTimeException6 ()
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);
904 // Directory.SetLastAccessTime (path, time);
906 // DeleteDirectory (path);
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
);
920 [ExpectedException(typeof(ArgumentException
))]
921 public void SetLastAccessTimeUtcException2 ()
923 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
924 Directory
.SetLastAccessTimeUtc ("", time
);
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
);
935 Directory
.SetLastAccessTimeUtc (path
, time
);
937 DeleteDirectory (path
);
942 [ExpectedException(typeof(ArgumentException
))]
943 public void SetLastAccessTimeUtcException4 ()
945 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
946 Directory
.SetLastAccessTimeUtc (" ", time
);
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
);
958 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
959 // public void SetLastAccessTimeUtcException6 ()
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);
967 // Directory.SetLastAccessTimeUtc (path, time);
969 // DeleteDirectory (path);
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
);
981 [ExpectedException(typeof(ArgumentException
))]
982 public void SetCreationTimeException2 ()
984 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
985 Directory
.SetCreationTime ("", time
);
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
);
997 Directory
.SetCreationTime (path
, time
);
999 DeleteDirectory (path
);
1004 [ExpectedException(typeof(ArgumentException
))]
1005 public void SetCreationTimeException4 ()
1007 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
1008 Directory
.SetCreationTime (" ", time
);
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
);
1020 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
1021 // public void SetCreationTimeException6 ()
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);
1029 // Directory.SetCreationTime (path, time);
1030 // DeleteDirectory (path);
1032 // DeleteDirectory (path);
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
);
1046 [ExpectedException(typeof(ArgumentException
))]
1047 public void SetCreationTimeUtcException2 ()
1049 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
1050 Directory
.SetCreationTimeUtc ("", time
);
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
);
1062 Directory
.SetCreationTimeUtc (path
, time
);
1063 DeleteDirectory (path
);
1065 DeleteDirectory (path
);
1070 [ExpectedException(typeof(ArgumentException
))]
1071 public void SetCreationTimeUtcException4 ()
1073 DateTime time
= new DateTime (2003, 4, 6, 6, 4, 2);
1074 Directory
.SetCreationTimeUtc (" ", time
);
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
);
1086 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
1087 // public void SetCreationTimeUtcException6 ()
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);
1095 // Directory.SetCreationTimeUtc (path, time);
1096 // DeleteDirectory (path);
1098 // DeleteDirectory (path);
1103 public void GetDirectories ()
1105 string path
= TempFolder
;
1106 string DirPath
= TempFolder
+ Path
.DirectorySeparatorChar
+ ".GetDirectories";
1107 DeleteDirectory (DirPath
);
1110 Directory
.CreateDirectory (DirPath
);
1112 string [] dirs
= Directory
.GetDirectories (path
);
1114 foreach (string directory
in dirs
) {
1116 if (directory
== DirPath
)
1120 Assert ("Directory Not Found", false);
1122 DeleteDirectory (DirPath
);
1127 public void GetParentOfRootDirectory ()
1131 info
= Directory
.GetParent (Path
.GetPathRoot (Path
.GetTempPath ()));
1132 AssertEquals (null, info
);
1136 public void GetFiles ()
1138 string path
= TempFolder
;
1139 string DirPath
= TempFolder
+ Path
.DirectorySeparatorChar
+ ".GetFiles";
1140 if (File
.Exists (DirPath
))
1141 File
.Delete (DirPath
);
1144 File
.Create (DirPath
).Close ();
1145 string [] files
= Directory
.GetFiles (TempFolder
);
1146 foreach (string directory
in files
) {
1148 if (directory
== DirPath
)
1152 Assert ("File Not Found", false);
1154 if (File
.Exists (DirPath
))
1155 File
.Delete (DirPath
);
1161 [ExpectedException (typeof (ArgumentNullException
))]
1162 public void SetCurrentDirectoryNull ()
1164 Directory
.SetCurrentDirectory (null);
1168 [ExpectedException (typeof (ArgumentException
))]
1169 public void SetCurrentDirectoryEmpty ()
1171 Directory
.SetCurrentDirectory (String
.Empty
);
1175 [ExpectedException (typeof (ArgumentException
))]
1176 public void SetCurrentDirectoryWhitespace ()
1178 Directory
.SetCurrentDirectory (" ");
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);