2 // System.IO.Directory
\r
5 // Ville Palo (vi64pa@kolumbus.fi)
\r
7 // (C) 2003 Ville Palo
\r
9 // TODO: Find out why ArgumentOutOfRange tests does not release directories properly
\r
13 using System.Diagnostics;
\r
14 using System.Globalization;
\r
17 using System.Threading;
\r
19 using NUnit.Framework;
\r
21 namespace MonoTests.System.IO
\r
25 public class DirectoryTest
\r
27 string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");
\r
28 static readonly char DSC = Path.DirectorySeparatorChar;
\r
31 public void SetUp ()
\r
33 if (!Directory.Exists (TempFolder))
\r
34 Directory.CreateDirectory (TempFolder);
\r
36 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
\r
40 public void TearDown ()
\r
42 if (Directory.Exists (TempFolder))
\r
43 Directory.Delete (TempFolder, true);
\r
47 public void CreateDirectory ()
\r
49 string path = TempFolder + DSC + "DirectoryTest.Test.1";
\r
50 DeleteDirectory (path);
\r
52 DirectoryInfo info = Directory.CreateDirectory (path);
\r
53 Assert.IsTrue (info.Exists, "#1");
\r
54 Assert.AreEqual (".1", info.Extension, "#2");
\r
55 Assert.IsTrue (info.FullName.EndsWith ("DirectoryTest.Test.1"), "#3");
\r
56 Assert.AreEqual ("DirectoryTest.Test.1", info.Name, "#4");
\r
58 DeleteDirectory (path);
\r
63 public void CreateDirectoryNotSupportedException ()
\r
65 DeleteDirectory (":");
\r
67 DirectoryInfo info = Directory.CreateDirectory (":");
\r
69 } catch (ArgumentException ex) {
\r
70 // The path is not of a legal form
\r
71 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
72 Assert.IsNull (ex.InnerException, "#3");
\r
73 Assert.IsNotNull (ex.Message, "#4");
\r
74 Assert.IsNull (ex.ParamName, "#5");
\r
76 DeleteDirectory (":");
\r
80 public void CreateDirectory_Path_Null ()
\r
83 Directory.CreateDirectory (null as string);
\r
85 } catch (ArgumentNullException ex) {
\r
86 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
87 Assert.IsNull (ex.InnerException, "#3");
\r
88 Assert.IsNotNull (ex.Message, "#4");
\r
89 Assert.AreEqual ("path", ex.ParamName, "#5");
\r
94 public void CreateDirectory_Path_Empty ()
\r
97 Directory.CreateDirectory (string.Empty);
\r
99 } catch (ArgumentException ex) {
\r
100 // Path cannot be the empty string or all whitespace
\r
101 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
102 Assert.IsNull (ex.InnerException, "#3");
\r
103 Assert.IsNotNull (ex.Message, "#4");
\r
104 Assert.IsNull (ex.ParamName, "#5");
\r
109 public void CreateDirectory_Path_Whitespace ()
\r
112 Directory.CreateDirectory (" ");
\r
113 Assert.Fail ("#1");
\r
114 } catch (ArgumentException ex) {
\r
115 // The path is not of a legal form
\r
116 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
117 Assert.IsNull (ex.InnerException, "#3");
\r
118 Assert.IsNotNull (ex.Message, "#4");
\r
119 Assert.IsNull (ex.ParamName, "#5");
\r
124 public void CreateDirectory_Path_InvalidChars ()
\r
126 string path = TempFolder + DSC + "DirectoryTest.Test";
\r
127 DeleteDirectory (path);
\r
131 DirectoryInfo info = Directory.CreateDirectory (path);
\r
132 Assert.Fail ("#1");
\r
133 } catch (ArgumentException ex) {
\r
134 // The path contains illegal characters
\r
135 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
136 Assert.IsNull (ex.InnerException, "#3");
\r
137 Assert.IsNotNull (ex.Message, "#4");
\r
138 Assert.IsNull (ex.ParamName, "#5");
\r
140 DeleteDirectory (path);
\r
145 public void CreateDirectoryAlreadyExists ()
\r
147 string path = TempFolder + DSC + "DirectoryTest.Test.Exists";
\r
148 DeleteDirectory (path);
\r
150 DirectoryInfo info1 = Directory.CreateDirectory (path);
\r
151 DirectoryInfo info2 = Directory.CreateDirectory (path);
\r
153 Assert.IsTrue (info2.Exists, "#1");
\r
154 Assert.IsTrue (info2.FullName.EndsWith ("DirectoryTest.Test.Exists"), "#2");
\r
155 Assert.AreEqual ("DirectoryTest.Test.Exists", info2.Name, "#3");
\r
157 DeleteDirectory (path);
\r
162 public void CreateDirectoryAlreadyExistsAsFile ()
\r
164 string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";
\r
165 DeleteDirectory (path);
\r
168 FileStream fstream = File.Create (path);
\r
171 DirectoryInfo dinfo = Directory.CreateDirectory (path);
\r
173 Assert.Fail ("#1");
\r
174 } catch (IOException ex) {
\r
175 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
176 // exception message contains the path
\r
177 Assert.IsTrue (ex.Message.Contains (path), "#3");
\r
178 Assert.IsNull (ex.InnerException, "#4");
\r
180 Assert.IsFalse (dinfo.Exists, "#2");
\r
181 Assert.IsTrue (dinfo.FullName.EndsWith ("DirectoryTest.Test.ExistsAsFile"), "#3");
\r
182 Assert.AreEqual ("DirectoryTest.Test.ExistsAsFile", dinfo.Name, "#4");
\r
185 DeleteDirectory (path);
\r
191 public void Delete ()
\r
193 string path = TempFolder + DSC + "DirectoryTest.Test.Delete.1";
\r
194 DeleteDirectory (path);
\r
196 Directory.CreateDirectory (path);
\r
197 Assert.IsTrue (Directory.Exists (path), "#1");
\r
199 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
200 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#2");
\r
202 Directory.Delete (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
203 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#3");
\r
204 Assert.IsTrue (Directory.Exists (path), "#4");
\r
206 Directory.Delete (path);
\r
207 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#5");
\r
208 Assert.IsFalse (Directory.Exists (path), "#6");
\r
210 Directory.CreateDirectory (path);
\r
211 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
212 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#7");
\r
213 Assert.IsTrue (Directory.Exists (path), "#8");
\r
215 Directory.Delete (path, true);
\r
216 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#9");
\r
217 Assert.IsFalse (Directory.Exists (path), "#10");
\r
219 DeleteDirectory (path);
\r
224 [ExpectedException(typeof(ArgumentException))]
\r
225 public void DeleteArgumentException ()
\r
227 Directory.Delete (string.Empty);
\r
231 [ExpectedException(typeof(ArgumentException))]
\r
232 public void DeleteArgumentException2 ()
\r
234 Directory.Delete (" ");
\r
238 [ExpectedException(typeof(ArgumentException))]
\r
239 public void DeleteArgumentException3 ()
\r
241 string path = TempFolder + DSC + "DirectoryTest.Test.4";
\r
242 DeleteDirectory (path);
\r
244 path += Path.InvalidPathChars [0];
\r
245 Directory.Delete (path);
\r
249 [ExpectedException(typeof(ArgumentNullException))]
\r
250 public void DeleteArgumentNullException ()
\r
252 Directory.Delete (null as string);
\r
256 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
257 public void DeleteDirectoryNotFoundException ()
\r
259 string path = TempFolder + DSC + "DirectoryTest.Test.5";
\r
260 DeleteDirectory (path);
\r
262 Directory.Delete (path);
\r
266 [ExpectedException(typeof(IOException))]
\r
267 public void DeleteArgumentException4 ()
\r
269 string path = TempFolder + DSC + "DirectoryTest.Test.6";
\r
270 DeleteDirectory (path);
\r
271 FileStream s = null;
\r
272 Directory.CreateDirectory (path);
\r
274 s = File.Create (path + DSC + "DirectoryTest.Test.6");
\r
275 Directory.Delete (path);
\r
279 DeleteDirectory (path);
\r
284 public void DeleteDirectoryOnExistingFileName ()
\r
286 string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";
\r
287 DeleteDirectory (path);
\r
290 FileStream fstream = File.Create (path);
\r
293 Directory.Delete (path);
\r
294 Assert.Fail ("#1");
\r
296 catch (IOException ex) {
\r
297 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
298 // exception message DOES NOT contains the path
\r
299 Assert.IsFalse (ex.Message.IndexOf (path) >= 0, "#3");
\r
300 Assert.IsNull (ex.InnerException, "#4");
\r
303 DeleteDirectory (path);
\r
309 public void Exists ()
\r
311 Assert.IsFalse (Directory.Exists (null as string));
\r
314 #if !TARGET_JVM // We don't support yet the Process class.
\r
315 [Test] // bug #78239
\r
316 public void ExistsAccessDenied ()
\r
318 if (!RunningOnUnix)
\r
319 return; // this test does not work on Windows.
\r
321 string path = TempFolder + DSC + "ExistsAccessDenied";
\r
323 Directory.CreateDirectory (path);
\r
324 Process.Start ("/bin/chmod", "000 " + path).WaitForExit ();
\r
326 Assert.IsFalse (Directory.Exists(path + DSC + "b"));
\r
328 Process.Start ("/bin/chmod", "755 " + path).WaitForExit ();
\r
329 Directory.Delete (path);
\r
335 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
336 [ExpectedException(typeof(ArgumentNullException))]
\r
337 public void GetCreationTimeException1 ()
\r
339 Directory.GetCreationTime (null as string);
\r
343 [ExpectedException(typeof(ArgumentException))]
\r
344 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
345 public void GetCreationTimeException2 ()
\r
347 Directory.GetCreationTime (string.Empty);
\r
352 [ExpectedException(typeof(IOException))]
\r
354 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
355 public void GetCreationTimeException_NonExistingPath ()
\r
357 string path = TempFolder + DSC + "DirectoryTest.GetCreationTime.1";
\r
358 DeleteDirectory (path);
\r
360 DateTime time = Directory.GetCreationTime (path);
\r
363 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
364 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
365 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
366 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
367 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
368 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
369 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
372 DeleteDirectory (path);
\r
377 [ExpectedException(typeof(ArgumentException))]
\r
378 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
379 public void GetCreationTimeException4 ()
\r
381 Directory.GetCreationTime (" ");
\r
385 [ExpectedException(typeof(ArgumentException))]
\r
386 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
387 public void GetCreationTimeException5 ()
\r
389 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
393 [ExpectedException(typeof(ArgumentNullException))]
\r
394 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
395 public void GetCreationTimeUtcException1 ()
\r
397 Directory.GetCreationTimeUtc (null as string);
\r
401 [ExpectedException(typeof(ArgumentException))]
\r
402 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
403 public void GetCreationTimeUtcException2 ()
\r
405 Directory.GetCreationTimeUtc (string.Empty);
\r
410 [ExpectedException (typeof (IOException))]
\r
412 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
413 public void GetCreationTimeUtc_NonExistingPath ()
\r
415 string path = TempFolder + DSC + "DirectoryTest.GetCreationTimeUtc.1";
\r
416 DeleteDirectory (path);
\r
419 DateTime time = Directory.GetCreationTimeUtc (path);
\r
422 Assert.AreEqual (1601, time.Year, "#1");
\r
423 Assert.AreEqual (1, time.Month, "#2");
\r
424 Assert.AreEqual (1, time.Day, "#3");
\r
425 Assert.AreEqual (0, time.Hour, "#4");
\r
426 Assert.AreEqual (0, time.Second, "#5");
\r
427 Assert.AreEqual (0, time.Millisecond, "#6");
\r
430 DeleteDirectory (path);
\r
435 [ExpectedException(typeof(ArgumentException))]
\r
436 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
437 public void GetCreationTimeUtcException4 ()
\r
439 Directory.GetCreationTimeUtc (" ");
\r
443 [ExpectedException(typeof(ArgumentException))]
\r
444 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
445 public void GetCreationTimeUtcException5 ()
\r
447 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
451 [ExpectedException(typeof(ArgumentNullException))]
\r
452 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
453 public void GetLastAccessTime_Null ()
\r
455 Directory.GetLastAccessTime (null as string);
\r
459 [ExpectedException(typeof(ArgumentException))]
\r
460 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
461 public void GetLastAccessTimeException2 ()
\r
463 Directory.GetLastAccessTime (string.Empty);
\r
468 [ExpectedException (typeof (IOException))]
\r
470 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
471 public void GetLastAccessTime_NonExistingPath ()
\r
473 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTime.1";
\r
474 DeleteDirectory (path);
\r
477 DateTime time = Directory.GetLastAccessTime (path);
\r
480 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
481 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
482 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
483 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
484 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
485 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
486 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
489 DeleteDirectory (path);
\r
494 [ExpectedException(typeof(ArgumentException))]
\r
495 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
496 public void GetLastAccessTimeException4 ()
\r
498 Directory.GetLastAccessTime (" ");
\r
502 [ExpectedException(typeof(ArgumentException))]
\r
503 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
504 public void GetLastAccessTimeException5 ()
\r
506 Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
\r
510 [ExpectedException(typeof(ArgumentNullException))]
\r
511 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
512 public void GetLastAccessTimeUtc_Null ()
\r
514 Directory.GetLastAccessTimeUtc (null as string);
\r
518 [ExpectedException(typeof(ArgumentException))]
\r
519 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
520 public void GetLastAccessTimeUtcException2 ()
\r
522 Directory.GetLastAccessTimeUtc (string.Empty);
\r
527 [ExpectedException (typeof (IOException))]
\r
529 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
530 public void GetLastAccessTimeUtc_NonExistingPath ()
\r
532 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTimeUtc.1";
\r
533 DeleteDirectory (path);
\r
535 DateTime time = Directory.GetLastAccessTimeUtc (path);
\r
538 Assert.AreEqual (1601, time.Year, "#1");
\r
539 Assert.AreEqual (1, time.Month, "#2");
\r
540 Assert.AreEqual (1, time.Day, "#3");
\r
541 Assert.AreEqual (0, time.Hour, "#4");
\r
542 Assert.AreEqual (0, time.Second, "#5");
\r
543 Assert.AreEqual (0, time.Millisecond, "#6");
\r
546 DeleteDirectory (path);
\r
551 [ExpectedException(typeof(ArgumentException))]
\r
552 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
553 public void GetLastAccessTimeUtcException4 ()
\r
555 Directory.GetLastAccessTimeUtc (" ");
\r
559 [ExpectedException(typeof(ArgumentException))]
\r
560 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
561 public void GetLastAccessTimeUtcException5 ()
\r
563 Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
\r
567 [ExpectedException(typeof(ArgumentNullException))]
\r
568 public void GetLastWriteTimeException1 ()
\r
570 Directory.GetLastWriteTime (null as string);
\r
574 [ExpectedException(typeof(ArgumentException))]
\r
575 public void GetLastWriteTimeException2 ()
\r
577 Directory.GetLastWriteTime (string.Empty);
\r
582 [ExpectedException (typeof (IOException))]
\r
584 public void GetLastWriteTime_NonExistingPath ()
\r
586 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTime.1";
\r
587 DeleteDirectory (path);
\r
589 DateTime time = Directory.GetLastWriteTime (path);
\r
592 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
593 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
594 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
595 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
596 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
597 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
598 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
601 DeleteDirectory (path);
\r
606 [ExpectedException(typeof(ArgumentException))]
\r
607 public void GetLastWriteTimeException4 ()
\r
609 Directory.GetLastWriteTime (" ");
\r
613 [ExpectedException(typeof(ArgumentException))]
\r
614 public void GetLastWriteTimeException5 ()
\r
616 Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
\r
620 [ExpectedException(typeof(ArgumentNullException))]
\r
621 public void GetLastWriteTimeUtcException1 ()
\r
623 Directory.GetLastWriteTimeUtc (null as string);
\r
627 [ExpectedException(typeof(ArgumentException))]
\r
628 public void GetLastWriteTimeUtcException2 ()
\r
630 Directory.GetLastWriteTimeUtc (string.Empty);
\r
635 [ExpectedException (typeof (IOException))]
\r
637 public void GetLastWriteTimeUtc_NonExistingPath ()
\r
639 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTimeUtc.1";
\r
640 DeleteDirectory (path);
\r
642 DateTime time = Directory.GetLastWriteTimeUtc (path);
\r
645 Assert.AreEqual (1601, time.Year, "#1");
\r
646 Assert.AreEqual (1, time.Month, "#2");
\r
647 Assert.AreEqual (1, time.Day, "#3");
\r
648 Assert.AreEqual (0, time.Hour, "#4");
\r
649 Assert.AreEqual (0, time.Second, "#5");
\r
650 Assert.AreEqual (0, time.Millisecond, "#6");
\r
653 DeleteDirectory (path);
\r
659 [ExpectedException(typeof(ArgumentException))]
\r
660 public void GetLastWriteTimeUtcException4 ()
\r
662 Directory.GetLastWriteTimeUtc (" ");
\r
666 [ExpectedException(typeof(ArgumentException))]
\r
667 public void GetLastWriteTimeUtcException5 ()
\r
669 Directory.GetLastWriteTimeUtc (Path.InvalidPathChars[0].ToString ());
\r
673 public void Move_DestDirName_Empty ()
\r
676 Directory.Move (TempFolder, string.Empty);
\r
677 Assert.Fail ("#A1");
\r
678 } catch (ArgumentException ex) {
\r
679 // Empty file name is not legal
\r
680 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
681 Assert.IsNull (ex.InnerException, "#A3");
\r
682 Assert.IsNotNull (ex.Message, "#A4");
\r
683 Assert.IsNotNull (ex.ParamName, "#A5");
\r
684 Assert.AreEqual ("destDirName", ex.ParamName, "#A6");
\r
688 Directory.Move (TempFolder, " ");
\r
689 Assert.Fail ("#B1");
\r
690 } catch (ArgumentException ex) {
\r
691 // The path is not of a legal form
\r
692 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
693 Assert.IsNull (ex.InnerException, "#B3");
\r
694 Assert.IsNotNull (ex.Message, "#B4");
\r
699 public void Move_DestDirName_Null ()
\r
702 Directory.Move (TempFolder, (string) null);
\r
703 Assert.Fail ("#1");
\r
704 } catch (ArgumentNullException ex) {
\r
705 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
706 Assert.IsNull (ex.InnerException, "#3");
\r
707 Assert.IsNotNull (ex.Message, "#4");
\r
708 Assert.IsNotNull (ex.ParamName, "#5");
\r
709 Assert.AreEqual ("destDirName", ex.ParamName, "#6");
\r
714 public void Move_SourceDirName_Empty ()
\r
717 Directory.Move (string.Empty, TempFolder);
\r
718 Assert.Fail ("#A1");
\r
719 } catch (ArgumentException ex) {
\r
720 // Empty file name is not legal
\r
721 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
722 Assert.IsNull (ex.InnerException, "#A3");
\r
723 Assert.IsNotNull (ex.Message, "#A4");
\r
724 Assert.IsNotNull (ex.ParamName, "#A5");
\r
725 Assert.AreEqual ("sourceDirName", ex.ParamName, "#A6");
\r
729 Directory.Move (" ", TempFolder);
\r
730 Assert.Fail ("#B1");
\r
731 } catch (ArgumentException ex) {
\r
732 // The path is not of a legal form
\r
733 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
734 Assert.IsNull (ex.InnerException, "#B3");
\r
735 Assert.IsNotNull (ex.Message, "#B4");
\r
740 public void Move_SourceDirName_Null ()
\r
743 Directory.Move ((string) null, TempFolder);
\r
744 Assert.Fail ("#1");
\r
745 } catch (ArgumentNullException ex) {
\r
746 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
747 Assert.IsNull (ex.InnerException, "#3");
\r
748 Assert.IsNotNull (ex.Message, "#4");
\r
749 Assert.IsNotNull (ex.ParamName, "#5");
\r
750 Assert.AreEqual ("sourceDirName", ex.ParamName, "#6");
\r
755 public void MoveDirectory ()
\r
757 string path = TempFolder + DSC + "DirectoryTest.Test.9";
\r
758 string path2 = TempFolder + DSC + "DirectoryTest.Test.10";
\r
759 DeleteDirectory (path);
\r
760 DeleteDirectory (path2);
\r
762 Directory.CreateDirectory (path);
\r
763 Directory.CreateDirectory (path + DSC + "dir");
\r
764 Assert.IsTrue (Directory.Exists (path + DSC + "dir"), "#1");
\r
766 Directory.Move (path, path2);
\r
767 Assert.IsFalse (Directory.Exists (path + DSC + "dir"), "#2");
\r
768 Assert.IsTrue (Directory.Exists (path2 + DSC + "dir"), "#3");
\r
770 DeleteDirectory (path);
\r
771 DeleteDirectory (path2);
\r
772 if (Directory.Exists (path2 + DSC + "dir"))
\r
773 Directory.Delete (path2 + DSC + "dir", true);
\r
778 [ExpectedException (typeof (IOException))]
\r
779 public void MoveDirectory_Same ()
\r
781 string path = TempFolder + DSC + "DirectoryTest.Test.8";
\r
782 DeleteDirectory (path);
\r
784 Directory.Move (path, path);
\r
786 DeleteDirectory (path);
\r
791 public void MoveFile ()
\r
793 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
794 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
796 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
797 sw.Write ("temp1");
\r
799 Assert.IsFalse (File.Exists (tempFile2), "#1");
\r
800 Directory.Move (tempFile1, tempFile2);
\r
801 Assert.IsFalse (File.Exists (tempFile1), "#2");
\r
802 Assert.IsTrue (File.Exists (tempFile2), "#3");
\r
803 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
804 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#4");
\r
809 public void MoveFile_DestDir_Exists ()
\r
811 string tempFile = Path.Combine (TempFolder, "temp1.txt");
\r
812 string tempDir = Path.Combine (TempFolder, "temp2");
\r
814 using (StreamWriter sw = File.CreateText (tempFile)) {
\r
815 sw.Write ("temp1");
\r
817 Directory.CreateDirectory (tempDir);
\r
820 Directory.Move (tempFile, tempDir);
\r
821 Assert.Fail ("#A1");
\r
822 } catch (IOException ex) {
\r
823 // Cannot create a file when that file already exists
\r
824 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
825 Assert.IsNull (ex.InnerException, "#A3");
\r
826 Assert.IsNotNull (ex.Message, "#A4");
\r
829 Assert.IsTrue (File.Exists (tempFile), "#B1");
\r
830 Assert.IsFalse (File.Exists (tempDir), "#B2");
\r
831 Assert.IsTrue (Directory.Exists (tempDir), "#B3");
\r
835 public void MoveFile_DestFile_Exists ()
\r
837 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
838 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
840 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
841 sw.Write ("temp1");
\r
843 using (StreamWriter sw = File.CreateText (tempFile2)) {
\r
844 sw.Write ("temp2");
\r
848 Directory.Move (tempFile1, tempFile2);
\r
849 Assert.Fail ("#A1");
\r
850 } catch (IOException ex) {
\r
851 // Cannot create a file when that file already exists
\r
852 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
853 Assert.IsNull (ex.InnerException, "#A3");
\r
854 Assert.IsNotNull (ex.Message, "#A4");
\r
857 Assert.IsTrue (File.Exists (tempFile1), "#B1");
\r
858 using (StreamReader sr = File.OpenText (tempFile1)) {
\r
859 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#B2");
\r
862 Assert.IsTrue (File.Exists (tempFile2), "#C1");
\r
863 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
864 Assert.AreEqual ("temp2", sr.ReadToEnd (), "#C2");
\r
869 public void MoveFile_Same ()
\r
871 string tempFile = Path.Combine (TempFolder, "temp.txt");
\r
874 Directory.Move (tempFile, tempFile);
\r
875 Assert.Fail ("#1");
\r
876 } catch (IOException ex) {
\r
877 // Source and destination path must be different
\r
878 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
879 Assert.IsNull (ex.InnerException, "#3");
\r
880 Assert.IsNotNull (ex.Message, "#4");
\r
885 [ExpectedException(typeof(ArgumentException))]
\r
886 [Ignore ("On IA64, causes nunit to abort due to bug #76388")]
\r
887 public void MoveException4 ()
\r
889 string path = TempFolder + DSC + "DirectoryTest.Test.13";
\r
890 path += Path.InvalidPathChars [0];
\r
891 string path2 = TempFolder + DSC + "DirectoryTest.Test.13";
\r
892 DeleteDirectory (path);
\r
893 DeleteDirectory (path2);
\r
895 Directory.CreateDirectory (path2);
\r
896 Directory.Move (path2, path);
\r
898 DeleteDirectory (path);
\r
899 DeleteDirectory (path2);
\r
904 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
905 public void MoveException5 ()
\r
907 string path = TempFolder + DSC + "DirectoryTest.Test.14";
\r
908 DeleteDirectory (path);
\r
910 Directory.Move (path, path + "Test.Test");
\r
912 DeleteDirectory (path);
\r
913 DeleteDirectory (path + "Test.Test");
\r
918 [ExpectedException(typeof(IOException))]
\r
919 public void MoveDirectory_Dest_SubDir ()
\r
921 string path = TempFolder + DSC + "DirectoryTest.Test.15";
\r
922 DeleteDirectory (path);
\r
924 Directory.CreateDirectory (path);
\r
925 Directory.Move (path, path + DSC + "dir");
\r
927 DeleteDirectory (path);
\r
928 DeleteDirectory (path + DSC + "dir");
\r
933 [ExpectedException (typeof (IOException))]
\r
934 public void MoveDirectory_Dest_Exists ()
\r
936 string path = TempFolder + DSC + "DirectoryTest.Test.16";
\r
937 string path2 = TempFolder + DSC + "DirectoryTest.Test.17";
\r
939 DeleteDirectory (path);
\r
940 DeleteDirectory (path2);
\r
942 Directory.CreateDirectory (path);
\r
943 Directory.CreateDirectory (path2);
\r
944 Directory.Move (path, path2);
\r
946 DeleteDirectory (path);
\r
947 DeleteDirectory (path2);
\r
952 [Category("TargetJvmNotSupported")] // CreationTime not supported for TARGET_JVM
\r
953 public void CreationTime ()
\r
956 Assert.Ignore ("Unix doesn't support CreationTime");
\r
958 string path = TempFolder + DSC + "DirectoryTest.CreationTime.1";
\r
959 DeleteDirectory (path);
\r
962 Directory.CreateDirectory (path);
\r
963 Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
965 DateTime time = Directory.GetCreationTime (path);
\r
966 Assert.AreEqual (2003, time.Year, "#A1");
\r
967 Assert.AreEqual (6, time.Month, "#A2");
\r
968 Assert.AreEqual (4, time.Day, "#A3");
\r
969 Assert.AreEqual (6, time.Hour, "#A4");
\r
970 Assert.AreEqual (4, time.Minute, "#A5");
\r
971 Assert.AreEqual (0, time.Second, "#A6");
\r
973 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
\r
974 Assert.AreEqual (2003, time.Year, "#B1");
\r
975 Assert.AreEqual (6, time.Month, "#B2");
\r
976 Assert.AreEqual (4, time.Day, "#B3");
\r
977 Assert.AreEqual (6, time.Hour, "#B4");
\r
978 Assert.AreEqual (4, time.Minute, "#B5");
\r
979 Assert.AreEqual (0, time.Second, "#B6");
\r
981 Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
982 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
\r
983 Assert.AreEqual (2003, time.Year, "#C1");
\r
984 Assert.AreEqual (6, time.Month, "#C2");
\r
985 Assert.AreEqual (4, time.Day, "#C3");
\r
986 Assert.AreEqual (6, time.Hour, "#C4");
\r
987 Assert.AreEqual (4, time.Minute, "#C5");
\r
988 Assert.AreEqual (0, time.Second, "#C6");
\r
990 time = Directory.GetCreationTimeUtc (path);
\r
991 Assert.AreEqual (2003, time.Year, "#D1");
\r
992 Assert.AreEqual (6, time.Month, "#D2");
\r
993 Assert.AreEqual (4, time.Day, "#D3");
\r
994 Assert.AreEqual (6, time.Hour, "#D4");
\r
995 Assert.AreEqual (4, time.Minute, "#D5");
\r
996 Assert.AreEqual (0, time.Second, "#D6");
\r
998 DeleteDirectory (path);
\r
1003 [Category("TargetJvmNotSupported")] // LastAccessTime not supported for TARGET_JVM
\r
1004 public void LastAccessTime ()
\r
1006 string path = TempFolder + DSC + "DirectoryTest.AccessTime.1";
\r
1007 DeleteDirectory (path);
\r
1010 Directory.CreateDirectory (path);
\r
1011 Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1013 DateTime time = Directory.GetLastAccessTime (path);
\r
1014 Assert.AreEqual (2003, time.Year, "#A1");
\r
1015 Assert.AreEqual (6, time.Month, "#A2");
\r
1016 Assert.AreEqual (4, time.Day, "#A3");
\r
1017 Assert.AreEqual (6, time.Hour, "#A4");
\r
1018 Assert.AreEqual (4, time.Minute, "#A5");
\r
1019 Assert.AreEqual (0, time.Second, "#A6");
\r
1021 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
\r
1022 Assert.AreEqual (2003, time.Year, "#B1");
\r
1023 Assert.AreEqual (6, time.Month, "#B2");
\r
1024 Assert.AreEqual (4, time.Day, "#B3");
\r
1025 Assert.AreEqual (6, time.Hour, "#B4");
\r
1026 Assert.AreEqual (4, time.Minute, "#B5");
\r
1027 Assert.AreEqual (0, time.Second, "#B6");
\r
1029 Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1030 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
\r
1031 Assert.AreEqual (2003, time.Year, "#C1");
\r
1032 Assert.AreEqual (6, time.Month, "#C2");
\r
1033 Assert.AreEqual (4, time.Day, "#C3");
\r
1034 Assert.AreEqual (6, time.Hour, "#C4");
\r
1035 Assert.AreEqual (4, time.Minute, "#C5");
\r
1036 Assert.AreEqual (0, time.Second, "#C6");
\r
1038 time = Directory.GetLastAccessTimeUtc (path);
\r
1039 Assert.AreEqual (2003, time.Year, "#D1");
\r
1040 Assert.AreEqual (6, time.Month, "#D2");
\r
1041 Assert.AreEqual (4, time.Day, "#D3");
\r
1042 Assert.AreEqual (6, time.Hour, "#D4");
\r
1043 Assert.AreEqual (4, time.Minute, "#D5");
\r
1044 Assert.AreEqual (0, time.Second, "#D6");
\r
1046 DeleteDirectory (path);
\r
1051 public void LastWriteTime ()
\r
1053 string path = TempFolder + DSC + "DirectoryTest.WriteTime.1";
\r
1054 DeleteDirectory (path);
\r
1057 Directory.CreateDirectory (path);
\r
1058 Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1060 DateTime time = Directory.GetLastWriteTime (path);
\r
1061 Assert.AreEqual (2003, time.Year, "#A1");
\r
1062 Assert.AreEqual (6, time.Month, "#A2");
\r
1063 Assert.AreEqual (4, time.Day, "#A3");
\r
1064 Assert.AreEqual (6, time.Hour, "#A4");
\r
1065 Assert.AreEqual (4, time.Minute, "#A5");
\r
1066 Assert.AreEqual (0, time.Second, "#A6");
\r
1068 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
\r
1069 Assert.AreEqual (2003, time.Year, "#B1");
\r
1070 Assert.AreEqual (6, time.Month, "#B2");
\r
1071 Assert.AreEqual (4, time.Day, "#B3");
\r
1072 Assert.AreEqual (6, time.Hour, "#B4");
\r
1073 Assert.AreEqual (4, time.Minute, "#B5");
\r
1074 Assert.AreEqual (0, time.Second, "#B6");
\r
1076 Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1077 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
\r
1078 Assert.AreEqual (2003, time.Year, "#C1");
\r
1079 Assert.AreEqual (6, time.Month, "#C2");
\r
1080 Assert.AreEqual (4, time.Day, "#C3");
\r
1081 Assert.AreEqual (6, time.Hour, "#C4");
\r
1082 Assert.AreEqual (4, time.Minute, "#C5");
\r
1083 Assert.AreEqual (0, time.Second, "#C6");
\r
1085 time = Directory.GetLastWriteTimeUtc (path);
\r
1086 Assert.AreEqual (2003, time.Year, "#D1");
\r
1087 Assert.AreEqual (6, time.Month, "#D2");
\r
1088 Assert.AreEqual (4, time.Day, "#D3");
\r
1089 Assert.AreEqual (6, time.Hour, "#D4");
\r
1090 Assert.AreEqual (4, time.Minute, "#D5");
\r
1091 Assert.AreEqual (0, time.Second, "#D6");
\r
1093 DeleteDirectory (path);
\r
1098 [ExpectedException(typeof(ArgumentNullException))]
\r
1099 public void SetLastWriteTimeException1 ()
\r
1101 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1102 Directory.SetLastWriteTime (null as string, time);
\r
1106 [ExpectedException(typeof(ArgumentException))]
\r
1107 public void SetLastWriteTimeException2 ()
\r
1109 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1110 Directory.SetLastWriteTime (string.Empty, time);
\r
1114 [ExpectedException(typeof(FileNotFoundException))]
\r
1115 public void SetLastWriteTimeException3 ()
\r
1117 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1118 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTime.2";
\r
1119 DeleteDirectory (path);
\r
1121 Directory.SetLastWriteTime (path, time);
\r
1123 DeleteDirectory (path);
\r
1128 [ExpectedException(typeof(ArgumentException))]
\r
1129 public void SetLastWriteTimeException4 ()
\r
1131 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1132 Directory.SetLastWriteTime (" ", time);
\r
1136 [ExpectedException(typeof(ArgumentException))]
\r
1137 public void SetLastWriteTimeException5 ()
\r
1139 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1140 Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
\r
1144 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1145 // public void SetLastWriteTimeException6 ()
\r
1147 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1148 // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
\r
1151 // if (!Directory.Exists (path))
\r
1152 // Directory.CreateDirectory (path);
\r
1154 // Directory.SetLastWriteTime (path, time);
\r
1156 // DeleteDirectory (path);
\r
1162 [ExpectedException(typeof(ArgumentNullException))]
\r
1163 public void SetLastWriteTimeUtcException1 ()
\r
1165 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1166 Directory.SetLastWriteTimeUtc (null as string, time);
\r
1170 [ExpectedException(typeof(ArgumentException))]
\r
1171 public void SetLastWriteTimeUtcException2 ()
\r
1173 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1174 Directory.SetLastWriteTimeUtc (string.Empty, time);
\r
1178 [ExpectedException(typeof(FileNotFoundException))]
\r
1179 public void SetLastWriteTimeUtcException3 ()
\r
1181 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1182 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.2";
\r
1183 DeleteDirectory (path);
\r
1185 Directory.SetLastWriteTimeUtc (path, time);
\r
1187 DeleteDirectory (path);
\r
1192 [ExpectedException(typeof(ArgumentException))]
\r
1193 public void SetLastWriteTimeUtcException4 ()
\r
1195 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1196 Directory.SetLastWriteTimeUtc (" ", time);
\r
1200 [ExpectedException(typeof(ArgumentException))]
\r
1201 public void SetLastWriteTimeUtcException5 ()
\r
1203 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1204 Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1208 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1209 // public void SetLastWriteTimeUtcException6 ()
\r
1211 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1212 // string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.1";
\r
1214 // if (!Directory.Exists (path))
\r
1215 // Directory.CreateDirectory (path);
\r
1217 // Directory.SetLastWriteTimeUtc (path, time);
\r
1219 // DeleteDirectory (path);
\r
1224 [ExpectedException(typeof(ArgumentNullException))]
\r
1225 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1226 public void SetLastAccessTimeException1 ()
\r
1228 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1229 Directory.SetLastAccessTime (null as string, time);
\r
1233 [ExpectedException(typeof(ArgumentException))]
\r
1234 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1235 public void SetLastAccessTimeException2 ()
\r
1237 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1238 Directory.SetLastAccessTime (string.Empty, time);
\r
1242 [ExpectedException(typeof(FileNotFoundException))]
\r
1243 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1244 public void SetLastAccessTimeException3 ()
\r
1246 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1247 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.2";
\r
1248 DeleteDirectory (path);
\r
1250 Directory.SetLastAccessTime (path, time);
\r
1252 DeleteDirectory (path);
\r
1257 [ExpectedException(typeof(ArgumentException))]
\r
1258 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1259 public void SetLastAccessTimeException4 ()
\r
1261 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1262 Directory.SetLastAccessTime (" ", time);
\r
1266 [ExpectedException(typeof(ArgumentException))]
\r
1267 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1268 public void SetLastAccessTimeException5 ()
\r
1270 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1271 Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
\r
1275 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1276 // public void SetLastAccessTimeException6 ()
\r
1278 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1279 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.1";
\r
1281 // if (!Directory.Exists (path))
\r
1282 // Directory.CreateDirectory (path);
\r
1284 // Directory.SetLastAccessTime (path, time);
\r
1286 // DeleteDirectory (path);
\r
1292 [ExpectedException(typeof(ArgumentNullException))]
\r
1293 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1294 public void SetLastAccessTimeUtcException1 ()
\r
1296 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1297 Directory.SetLastAccessTimeUtc (null as string, time);
\r
1301 [ExpectedException(typeof(ArgumentException))]
\r
1302 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1303 public void SetLastAccessTimeUtcException2 ()
\r
1305 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1306 Directory.SetLastAccessTimeUtc (string.Empty, time);
\r
1310 [ExpectedException(typeof(FileNotFoundException))]
\r
1311 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1312 public void SetLastAccessTimeUtcException3 ()
\r
1314 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1315 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1316 DeleteDirectory (path);
\r
1318 Directory.SetLastAccessTimeUtc (path, time);
\r
1320 DeleteDirectory (path);
\r
1325 [ExpectedException(typeof(ArgumentException))]
\r
1326 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1327 public void SetLastAccessTimeUtcException4 ()
\r
1329 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1330 Directory.SetLastAccessTimeUtc (" ", time);
\r
1334 [ExpectedException(typeof(ArgumentException))]
\r
1335 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1336 public void SetLastAccessTimeUtcException5 ()
\r
1338 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1339 Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1343 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1344 // public void SetLastAccessTimeUtcException6 ()
\r
1346 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1347 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1349 // if (!Directory.Exists (path))
\r
1350 // Directory.CreateDirectory (path);
\r
1352 // Directory.SetLastAccessTimeUtc (path, time);
\r
1354 // DeleteDirectory (path);
\r
1359 [ExpectedException(typeof(ArgumentNullException))]
\r
1360 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1361 public void SetCreationTimeException1 ()
\r
1363 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1364 Directory.SetCreationTime (null as string, time);
\r
1368 [ExpectedException(typeof(ArgumentException))]
\r
1369 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1370 public void SetCreationTimeException2 ()
\r
1372 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1373 Directory.SetCreationTime (string.Empty, time);
\r
1377 [ExpectedException(typeof(FileNotFoundException))]
\r
1378 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1379 public void SetCreationTimeException3 ()
\r
1381 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1382 string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.2";
\r
1383 DeleteDirectory (path);
\r
1386 Directory.SetCreationTime (path, time);
\r
1388 DeleteDirectory (path);
\r
1393 [ExpectedException(typeof(ArgumentException))]
\r
1394 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1395 public void SetCreationTimeException4 ()
\r
1397 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1398 Directory.SetCreationTime (" ", time);
\r
1402 [ExpectedException(typeof(ArgumentException))]
\r
1403 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1404 public void SetCreationTimeException5 ()
\r
1406 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1407 Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
\r
1411 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1412 // public void SetCreationTimeException6 ()
\r
1414 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1415 // string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.1";
\r
1417 // if (!Directory.Exists (path))
\r
1418 // Directory.CreateDirectory (path);
\r
1420 // Directory.SetCreationTime (path, time);
\r
1421 // DeleteDirectory (path);
\r
1423 // DeleteDirectory (path);
\r
1429 [ExpectedException(typeof(ArgumentNullException))]
\r
1430 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1431 public void SetCreationTimeUtcException1 ()
\r
1433 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1434 Directory.SetCreationTimeUtc (null as string, time);
\r
1438 [ExpectedException(typeof(ArgumentException))]
\r
1439 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1440 public void SetCreationTimeUtcException2 ()
\r
1442 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1443 Directory.SetCreationTimeUtc (string.Empty, time);
\r
1447 [ExpectedException(typeof(FileNotFoundException))]
\r
1448 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1449 public void SetCreationTimeUtcException3 ()
\r
1451 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1452 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1453 DeleteDirectory (path);
\r
1456 Directory.SetCreationTimeUtc (path, time);
\r
1457 DeleteDirectory (path);
\r
1459 DeleteDirectory (path);
\r
1464 [ExpectedException(typeof(ArgumentException))]
\r
1465 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1466 public void SetCreationTimeUtcException4 ()
\r
1468 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1469 Directory.SetCreationTimeUtc (" ", time);
\r
1473 [ExpectedException(typeof(ArgumentException))]
\r
1474 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1475 public void SetCreationTimeUtcException5 ()
\r
1477 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1478 Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1482 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1483 // public void SetCreationTimeUtcException6 ()
\r
1485 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1486 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1488 // if (!Directory.Exists (path))
\r
1489 // Directory.CreateDirectory (path);
\r
1491 // Directory.SetCreationTimeUtc (path, time);
\r
1492 // DeleteDirectory (path);
\r
1494 // DeleteDirectory (path);
\r
1499 public void GetDirectories ()
\r
1501 string path = TempFolder;
\r
1502 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetDirectories";
\r
1503 DeleteDirectory (DirPath);
\r
1506 Directory.CreateDirectory (DirPath);
\r
1508 string [] dirs = Directory.GetDirectories (path);
\r
1510 foreach (string directory in dirs) {
\r
1512 if (directory == DirPath)
\r
1516 Assert.Fail ("Directory Not Found");
\r
1518 DeleteDirectory (DirPath);
\r
1522 [Test] // bug #346123
\r
1523 public void GetDirectories_Backslash ()
\r
1525 if (!RunningOnUnix)
\r
1526 // on Windows, backslash is used as directory separator
\r
1529 string dir = Path.Combine (TempFolder, @"sub\dir");
\r
1530 Directory.CreateDirectory (dir);
\r
1532 Assert.IsTrue (Directory.Exists (dir), "#A1");
\r
1533 Assert.IsFalse (Directory.Exists (Path.Combine (TempFolder, "dir")), "#A2");
\r
1535 string [] dirs = Directory.GetDirectories (TempFolder);
\r
1536 Assert.AreEqual (1, dirs.Length, "#B1");
\r
1537 Assert.AreEqual (dir, dirs [0], "#B2");
\r
1541 public void GetParentOfRootDirectory ()
\r
1543 DirectoryInfo info;
\r
1545 info = Directory.GetParent (Path.GetPathRoot (Path.GetTempPath ()));
\r
1546 Assert.IsNull (info);
\r
1550 public void GetFiles ()
\r
1552 string path = TempFolder;
\r
1553 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetFiles";
\r
1554 if (File.Exists (DirPath))
\r
1555 File.Delete (DirPath);
\r
1558 File.Create (DirPath).Close ();
\r
1559 string [] files = Directory.GetFiles (TempFolder);
\r
1560 foreach (string directory in files) {
\r
1562 if (directory == DirPath)
\r
1566 Assert.Fail ("File Not Found");
\r
1568 if (File.Exists (DirPath))
\r
1569 File.Delete (DirPath);
\r
1573 [Test] // bug #346123
\r
1574 public void GetFiles_Backslash ()
\r
1576 if (!RunningOnUnix)
\r
1577 // on Windows, backslash is used as directory separator
\r
1580 string file = Path.Combine (TempFolder, @"doc\temp1.file");
\r
1581 File.Create (file).Close ();
\r
1583 Assert.IsTrue (File.Exists (file), "#A1");
\r
1584 Assert.IsFalse (File.Exists (Path.Combine (TempFolder, "temp1.file")), "#A2");
\r
1586 string [] files = Directory.GetFiles (TempFolder);
\r
1587 Assert.AreEqual (1, files.Length, "#B1");
\r
1588 Assert.AreEqual (file, files [0], "#B2");
\r
1591 [Test] // bug #82212 and bug #325107
\r
1592 public void GetFiles_Pattern ()
\r
1594 string [] files = Directory.GetFiles (TempFolder, "*.*");
\r
1595 Assert.IsNotNull (files, "#A1");
\r
1596 Assert.AreEqual (0, files.Length, "#A2");
\r
1598 string tempFile1 = Path.Combine (TempFolder, "tempFile1");
\r
1599 File.Create (tempFile1).Close ();
\r
1601 files = Directory.GetFiles (TempFolder, "*.*");
\r
1602 Assert.IsNotNull (files, "#B1");
\r
1603 Assert.AreEqual (1, files.Length, "#B2");
\r
1604 Assert.AreEqual (tempFile1, files [0], "#B3");
\r
1606 string tempFile2 = Path.Combine (TempFolder, "FileTemp2.tmp");
\r
1607 File.Create (tempFile2).Close ();
\r
1609 files = Directory.GetFiles (TempFolder, "*.*");
\r
1610 Assert.IsNotNull (files, "#C1");
\r
1611 Assert.AreEqual (2, files.Length, "#C2");
\r
1613 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1614 Assert.IsNotNull (files, "#D1");
\r
1615 Assert.AreEqual (1, files.Length, "#D2");
\r
1616 Assert.AreEqual (tempFile1, files [0], "#D3");
\r
1618 string tempFile3 = Path.Combine (TempFolder, "tempFile3.txt");
\r
1619 File.Create (tempFile3).Close ();
\r
1621 files = Directory.GetFiles (TempFolder, "*File*.*");
\r
1622 Assert.IsNotNull (files, "#E1");
\r
1623 Assert.AreEqual (3, files.Length, "#E2");
\r
1625 files = Directory.GetFiles (TempFolder, "*File*.tmp");
\r
1626 Assert.IsNotNull (files, "#F1");
\r
1627 Assert.AreEqual (1, files.Length, "#F2");
\r
1628 Assert.AreEqual (tempFile2, files [0], "#F3");
\r
1630 files = Directory.GetFiles (TempFolder, "*tempFile*");
\r
1631 Assert.IsNotNull (files, "#G1");
\r
1632 Assert.AreEqual (2, files.Length, "#G2");
\r
1634 files = Directory.GetFiles (TempFolder, "*tempFile1");
\r
1635 Assert.IsNotNull (files, "#H1");
\r
1636 Assert.AreEqual (1, files.Length, "#H2");
\r
1637 Assert.AreEqual (tempFile1, files [0], "#H3");
\r
1639 files = Directory.GetFiles (TempFolder, "*.txt");
\r
1640 Assert.IsNotNull (files, "#I1");
\r
1641 Assert.AreEqual (1, files.Length, "#I2");
\r
1642 Assert.AreEqual (tempFile3, files [0], "#I3");
\r
1644 files = Directory.GetFiles (TempFolder, "*.t*");
\r
1645 Assert.IsNotNull (files, "#J1");
\r
1646 Assert.AreEqual (2, files.Length, "#J2");
\r
1648 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1649 Assert.IsNotNull (files, "#K1");
\r
1650 Assert.AreEqual (2, files.Length, "#K2");
\r
1652 File.Delete (tempFile1);
\r
1654 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1655 Assert.IsNotNull (files, "#L1");
\r
1656 Assert.AreEqual (1, files.Length, "#L2");
\r
1657 Assert.AreEqual (tempFile3, files [0], "#L3");
\r
1659 files = Directory.GetFiles (TempFolder, ".*");
\r
1660 Assert.IsNotNull (files, "#M1");
\r
1661 Assert.AreEqual (0, files.Length, "#M2");
\r
1663 string tempFile4 = Path.Combine (TempFolder, "tempFile4.");
\r
1664 File.Create (tempFile4).Close ();
\r
1666 files = Directory.GetFiles (TempFolder, "temp*.");
\r
1667 Assert.IsNotNull (files, "#N1");
\r
1668 Assert.AreEqual (1, files.Length, "#N2");
\r
1669 if (RunningOnUnix)
\r
1670 Assert.AreEqual (tempFile4, files [0], "#N3");
\r
1671 else // on Windows, the trailing dot is automatically trimmed
\r
1672 Assert.AreEqual (Path.Combine (TempFolder, "tempFile4"), files [0], "#N3");
\r
1676 [ExpectedException (typeof (ArgumentNullException))]
\r
1677 public void SetCurrentDirectoryNull ()
\r
1679 Directory.SetCurrentDirectory (null);
\r
1683 [ExpectedException (typeof (ArgumentException))]
\r
1684 public void SetCurrentDirectoryEmpty ()
\r
1686 Directory.SetCurrentDirectory (String.Empty);
\r
1690 [ExpectedException (typeof (ArgumentException))]
\r
1691 public void SetCurrentDirectoryWhitespace ()
\r
1693 Directory.SetCurrentDirectory (" ");
\r
1698 public void GetNoFiles () // Bug 58875. This throwed an exception on windows.
\r
1700 DirectoryInfo dir = new DirectoryInfo (".");
\r
1701 dir.GetFiles ("*.nonext");
\r
1705 public void FilenameOnly () // bug 78209
\r
1707 Directory.GetParent ("somefile");
\r
1710 private static bool RunningOnUnix {
\r
1712 // check for Unix platforms - see FAQ for more details
\r
1713 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
\r
1714 int platform = (int) Environment.OSVersion.Platform;
\r
1715 return ((platform == 4) || (platform == 128) || (platform == 6));
\r
1719 private void DeleteDirectory (string path)
\r
1721 if (Directory.Exists (path))
\r
1722 Directory.Delete (path, true);
\r
1725 private void DeleteFile (string path)
\r
1727 if (File.Exists (path))
\r
1728 File.Delete (path);
\r