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 static readonly string TempSubFolder = "MonoTests.System.IO.Tests";
\r
28 string TempFolder = Path.Combine (Path.GetTempPath (), TempSubFolder);
\r
29 static readonly char DSC = Path.DirectorySeparatorChar;
\r
32 public void SetUp ()
\r
34 if (!Directory.Exists (TempFolder))
\r
35 Directory.CreateDirectory (TempFolder);
\r
37 Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
\r
41 public void TearDown ()
\r
43 if (Directory.Exists (TempFolder))
\r
44 Directory.Delete (TempFolder, true);
\r
48 public void CreateDirectory ()
\r
50 string path = TempFolder + DSC + "DirectoryTest.Test.1";
\r
51 DeleteDirectory (path);
\r
53 DirectoryInfo info = Directory.CreateDirectory (path);
\r
54 Assert.IsTrue (info.Exists, "#1");
\r
55 Assert.AreEqual (".1", info.Extension, "#2");
\r
56 Assert.IsTrue (info.FullName.EndsWith ("DirectoryTest.Test.1"), "#3");
\r
57 Assert.AreEqual ("DirectoryTest.Test.1", info.Name, "#4");
\r
59 DeleteDirectory (path);
\r
63 /* Commented out: a directory named ":" is legal in unix
\r
65 public void CreateDirectoryNotSupportedException ()
\r
67 DeleteDirectory (":");
\r
69 DirectoryInfo info = Directory.CreateDirectory (":");
\r
71 } catch (ArgumentException ex) {
\r
72 // The path is not of a legal form
\r
73 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
74 Assert.IsNull (ex.InnerException, "#3");
\r
75 Assert.IsNotNull (ex.Message, "#4");
\r
76 Assert.IsNull (ex.ParamName, "#5");
\r
78 DeleteDirectory (":");
\r
83 public void CreateDirectory_Path_Null ()
\r
86 Directory.CreateDirectory (null as string);
\r
88 } catch (ArgumentNullException ex) {
\r
89 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
90 Assert.IsNull (ex.InnerException, "#3");
\r
91 Assert.IsNotNull (ex.Message, "#4");
\r
92 Assert.AreEqual ("path", ex.ParamName, "#5");
\r
97 public void CreateDirectory_Path_Empty ()
\r
100 Directory.CreateDirectory (string.Empty);
\r
101 Assert.Fail ("#1");
\r
102 } catch (ArgumentException ex) {
\r
103 // Path cannot be the empty string or all whitespace
\r
104 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
105 Assert.IsNull (ex.InnerException, "#3");
\r
106 Assert.IsNotNull (ex.Message, "#4");
\r
107 Assert.IsNull (ex.ParamName, "#5");
\r
112 public void CreateDirectory_Path_Whitespace ()
\r
115 Directory.CreateDirectory (" ");
\r
116 Assert.Fail ("#1");
\r
117 } catch (ArgumentException ex) {
\r
118 // The path is not of a legal form
\r
119 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
120 Assert.IsNull (ex.InnerException, "#3");
\r
121 Assert.IsNotNull (ex.Message, "#4");
\r
122 Assert.IsNull (ex.ParamName, "#5");
\r
127 public void CreateDirectory_Path_InvalidChars ()
\r
129 string path = TempFolder + DSC + "DirectoryTest.Test";
\r
130 DeleteDirectory (path);
\r
134 DirectoryInfo info = Directory.CreateDirectory (path);
\r
135 Assert.Fail ("#1");
\r
136 } catch (ArgumentException ex) {
\r
137 // The path contains illegal characters
\r
138 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
\r
139 Assert.IsNull (ex.InnerException, "#3");
\r
140 Assert.IsNotNull (ex.Message, "#4");
\r
141 Assert.IsNull (ex.ParamName, "#5");
\r
143 DeleteDirectory (path);
\r
148 public void CreateDirectoryAlreadyExists ()
\r
150 string path = TempFolder + DSC + "DirectoryTest.Test.Exists";
\r
151 DeleteDirectory (path);
\r
153 DirectoryInfo info1 = Directory.CreateDirectory (path);
\r
154 DirectoryInfo info2 = Directory.CreateDirectory (path);
\r
156 Assert.IsTrue (info2.Exists, "#1");
\r
157 Assert.IsTrue (info2.FullName.EndsWith ("DirectoryTest.Test.Exists"), "#2");
\r
158 Assert.AreEqual ("DirectoryTest.Test.Exists", info2.Name, "#3");
\r
160 DeleteDirectory (path);
\r
165 public void CreateDirectoryAlreadyExistsAsFile ()
\r
167 string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";
\r
168 DeleteDirectory (path);
\r
171 FileStream fstream = File.Create (path);
\r
174 DirectoryInfo dinfo = Directory.CreateDirectory (path);
\r
176 Assert.Fail ("#1");
\r
177 } catch (IOException ex) {
\r
178 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
179 // exception message contains the path
\r
180 Assert.IsTrue (ex.Message.Contains (path), "#3");
\r
181 Assert.IsNull (ex.InnerException, "#4");
\r
183 Assert.IsFalse (dinfo.Exists, "#2");
\r
184 Assert.IsTrue (dinfo.FullName.EndsWith ("DirectoryTest.Test.ExistsAsFile"), "#3");
\r
185 Assert.AreEqual ("DirectoryTest.Test.ExistsAsFile", dinfo.Name, "#4");
\r
188 DeleteDirectory (path);
\r
194 public void Delete ()
\r
196 string path = TempFolder + DSC + "DirectoryTest.Test.Delete.1";
\r
197 DeleteDirectory (path);
\r
199 Directory.CreateDirectory (path);
\r
200 Assert.IsTrue (Directory.Exists (path), "#1");
\r
202 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
203 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#2");
\r
205 Directory.Delete (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
206 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#3");
\r
207 Assert.IsTrue (Directory.Exists (path), "#4");
\r
209 Directory.Delete (path);
\r
210 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#5");
\r
211 Assert.IsFalse (Directory.Exists (path), "#6");
\r
213 Directory.CreateDirectory (path);
\r
214 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
215 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#7");
\r
216 Assert.IsTrue (Directory.Exists (path), "#8");
\r
218 Directory.Delete (path, true);
\r
219 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#9");
\r
220 Assert.IsFalse (Directory.Exists (path), "#10");
\r
222 DeleteDirectory (path);
\r
227 [ExpectedException(typeof(ArgumentException))]
\r
228 public void DeleteArgumentException ()
\r
230 Directory.Delete (string.Empty);
\r
234 [ExpectedException(typeof(ArgumentException))]
\r
235 public void DeleteArgumentException2 ()
\r
237 Directory.Delete (" ");
\r
241 [ExpectedException(typeof(ArgumentException))]
\r
242 public void DeleteArgumentException3 ()
\r
244 string path = TempFolder + DSC + "DirectoryTest.Test.4";
\r
245 DeleteDirectory (path);
\r
247 path += Path.InvalidPathChars [0];
\r
248 Directory.Delete (path);
\r
252 [ExpectedException(typeof(ArgumentNullException))]
\r
253 public void DeleteArgumentNullException ()
\r
255 Directory.Delete (null as string);
\r
259 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
260 public void DeleteDirectoryNotFoundException ()
\r
262 string path = TempFolder + DSC + "DirectoryTest.Test.5";
\r
263 DeleteDirectory (path);
\r
265 Directory.Delete (path);
\r
269 [ExpectedException(typeof(IOException))]
\r
270 public void DeleteArgumentException4 ()
\r
272 string path = TempFolder + DSC + "DirectoryTest.Test.6";
\r
273 DeleteDirectory (path);
\r
274 FileStream s = null;
\r
275 Directory.CreateDirectory (path);
\r
277 s = File.Create (path + DSC + "DirectoryTest.Test.6");
\r
278 Directory.Delete (path);
\r
282 DeleteDirectory (path);
\r
287 public void DeleteDirectoryOnExistingFileName ()
\r
289 string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";
\r
290 DeleteDirectory (path);
\r
293 FileStream fstream = File.Create (path);
\r
296 Directory.Delete (path);
\r
297 Assert.Fail ("#1");
\r
299 catch (IOException ex) {
\r
300 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
301 // exception message DOES NOT contains the path
\r
302 Assert.IsFalse (ex.Message.IndexOf (path) >= 0, "#3");
\r
303 Assert.IsNull (ex.InnerException, "#4");
\r
306 DeleteDirectory (path);
\r
312 public void Exists ()
\r
314 Assert.IsFalse (Directory.Exists (null as string));
\r
317 #if !TARGET_JVM // We don't support yet the Process class.
\r
318 [Test] // bug #78239
\r
319 public void ExistsAccessDenied ()
\r
321 if (!RunningOnUnix)
\r
322 return; // this test does not work on Windows.
\r
324 string path = TempFolder + DSC + "ExistsAccessDenied";
\r
326 Directory.CreateDirectory (path);
\r
327 Mono.Posix.Syscall.chmod (path, 0);
\r
329 Assert.IsFalse (Directory.Exists(path + DSC + "b"));
\r
331 Mono.Posix.Syscall.chmod (path, (Mono.Posix.FileMode) 755);
\r
332 Directory.Delete (path);
\r
338 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
339 [ExpectedException(typeof(ArgumentNullException))]
\r
340 public void GetCreationTimeException1 ()
\r
342 Directory.GetCreationTime (null as string);
\r
346 [ExpectedException(typeof(ArgumentException))]
\r
347 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
348 public void GetCreationTimeException2 ()
\r
350 Directory.GetCreationTime (string.Empty);
\r
355 [ExpectedException(typeof(IOException))]
\r
357 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
358 public void GetCreationTimeException_NonExistingPath ()
\r
360 string path = TempFolder + DSC + "DirectoryTest.GetCreationTime.1";
\r
361 DeleteDirectory (path);
\r
363 DateTime time = Directory.GetCreationTime (path);
\r
366 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
367 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
368 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
369 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
370 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
371 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
372 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
375 DeleteDirectory (path);
\r
380 [ExpectedException(typeof(ArgumentException))]
\r
381 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
382 public void GetCreationTimeException4 ()
\r
384 Directory.GetCreationTime (" ");
\r
388 [ExpectedException(typeof(ArgumentException))]
\r
389 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
390 public void GetCreationTimeException5 ()
\r
392 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
396 [ExpectedException(typeof(ArgumentNullException))]
\r
397 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
398 public void GetCreationTimeUtcException1 ()
\r
400 Directory.GetCreationTimeUtc (null as string);
\r
404 [ExpectedException(typeof(ArgumentException))]
\r
405 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
406 public void GetCreationTimeUtcException2 ()
\r
408 Directory.GetCreationTimeUtc (string.Empty);
\r
413 [ExpectedException (typeof (IOException))]
\r
415 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
416 public void GetCreationTimeUtc_NonExistingPath ()
\r
418 string path = TempFolder + DSC + "DirectoryTest.GetCreationTimeUtc.1";
\r
419 DeleteDirectory (path);
\r
422 DateTime time = Directory.GetCreationTimeUtc (path);
\r
425 Assert.AreEqual (1601, time.Year, "#1");
\r
426 Assert.AreEqual (1, time.Month, "#2");
\r
427 Assert.AreEqual (1, time.Day, "#3");
\r
428 Assert.AreEqual (0, time.Hour, "#4");
\r
429 Assert.AreEqual (0, time.Second, "#5");
\r
430 Assert.AreEqual (0, time.Millisecond, "#6");
\r
433 DeleteDirectory (path);
\r
438 [ExpectedException(typeof(ArgumentException))]
\r
439 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
440 public void GetCreationTimeUtcException4 ()
\r
442 Directory.GetCreationTimeUtc (" ");
\r
446 [ExpectedException(typeof(ArgumentException))]
\r
447 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
448 public void GetCreationTimeUtcException5 ()
\r
450 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
454 [ExpectedException(typeof(ArgumentNullException))]
\r
455 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
456 public void GetLastAccessTime_Null ()
\r
458 Directory.GetLastAccessTime (null as string);
\r
462 [ExpectedException(typeof(ArgumentException))]
\r
463 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
464 public void GetLastAccessTimeException2 ()
\r
466 Directory.GetLastAccessTime (string.Empty);
\r
471 [ExpectedException (typeof (IOException))]
\r
473 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
474 public void GetLastAccessTime_NonExistingPath ()
\r
476 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTime.1";
\r
477 DeleteDirectory (path);
\r
480 DateTime time = Directory.GetLastAccessTime (path);
\r
483 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
484 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
485 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
486 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
487 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
488 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
489 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
492 DeleteDirectory (path);
\r
497 [ExpectedException(typeof(ArgumentException))]
\r
498 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
499 public void GetLastAccessTimeException4 ()
\r
501 Directory.GetLastAccessTime (" ");
\r
505 [ExpectedException(typeof(ArgumentException))]
\r
506 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
507 public void GetLastAccessTimeException5 ()
\r
509 Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
\r
513 [ExpectedException(typeof(ArgumentNullException))]
\r
514 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
515 public void GetLastAccessTimeUtc_Null ()
\r
517 Directory.GetLastAccessTimeUtc (null as string);
\r
521 [ExpectedException(typeof(ArgumentException))]
\r
522 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
523 public void GetLastAccessTimeUtcException2 ()
\r
525 Directory.GetLastAccessTimeUtc (string.Empty);
\r
530 [ExpectedException (typeof (IOException))]
\r
532 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
533 public void GetLastAccessTimeUtc_NonExistingPath ()
\r
535 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTimeUtc.1";
\r
536 DeleteDirectory (path);
\r
538 DateTime time = Directory.GetLastAccessTimeUtc (path);
\r
541 Assert.AreEqual (1601, time.Year, "#1");
\r
542 Assert.AreEqual (1, time.Month, "#2");
\r
543 Assert.AreEqual (1, time.Day, "#3");
\r
544 Assert.AreEqual (0, time.Hour, "#4");
\r
545 Assert.AreEqual (0, time.Second, "#5");
\r
546 Assert.AreEqual (0, time.Millisecond, "#6");
\r
549 DeleteDirectory (path);
\r
554 [ExpectedException(typeof(ArgumentException))]
\r
555 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
556 public void GetLastAccessTimeUtcException4 ()
\r
558 Directory.GetLastAccessTimeUtc (" ");
\r
562 [ExpectedException(typeof(ArgumentException))]
\r
563 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
564 public void GetLastAccessTimeUtcException5 ()
\r
566 Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
\r
570 [ExpectedException(typeof(ArgumentNullException))]
\r
571 public void GetLastWriteTimeException1 ()
\r
573 Directory.GetLastWriteTime (null as string);
\r
577 [ExpectedException(typeof(ArgumentException))]
\r
578 public void GetLastWriteTimeException2 ()
\r
580 Directory.GetLastWriteTime (string.Empty);
\r
585 [ExpectedException (typeof (IOException))]
\r
587 public void GetLastWriteTime_NonExistingPath ()
\r
589 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTime.1";
\r
590 DeleteDirectory (path);
\r
592 DateTime time = Directory.GetLastWriteTime (path);
\r
595 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
596 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
597 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
598 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
599 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
600 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
601 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
604 DeleteDirectory (path);
\r
609 [ExpectedException(typeof(ArgumentException))]
\r
610 public void GetLastWriteTimeException4 ()
\r
612 Directory.GetLastWriteTime (" ");
\r
616 [ExpectedException(typeof(ArgumentException))]
\r
617 public void GetLastWriteTimeException5 ()
\r
619 Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
\r
623 [ExpectedException(typeof(ArgumentNullException))]
\r
624 public void GetLastWriteTimeUtcException1 ()
\r
626 Directory.GetLastWriteTimeUtc (null as string);
\r
630 [ExpectedException(typeof(ArgumentException))]
\r
631 public void GetLastWriteTimeUtcException2 ()
\r
633 Directory.GetLastWriteTimeUtc (string.Empty);
\r
638 [ExpectedException (typeof (IOException))]
\r
640 public void GetLastWriteTimeUtc_NonExistingPath ()
\r
642 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTimeUtc.1";
\r
643 DeleteDirectory (path);
\r
645 DateTime time = Directory.GetLastWriteTimeUtc (path);
\r
648 Assert.AreEqual (1601, time.Year, "#1");
\r
649 Assert.AreEqual (1, time.Month, "#2");
\r
650 Assert.AreEqual (1, time.Day, "#3");
\r
651 Assert.AreEqual (0, time.Hour, "#4");
\r
652 Assert.AreEqual (0, time.Second, "#5");
\r
653 Assert.AreEqual (0, time.Millisecond, "#6");
\r
656 DeleteDirectory (path);
\r
662 [ExpectedException(typeof(ArgumentException))]
\r
663 public void GetLastWriteTimeUtcException4 ()
\r
665 Directory.GetLastWriteTimeUtc (" ");
\r
669 [ExpectedException(typeof(ArgumentException))]
\r
670 public void GetLastWriteTimeUtcException5 ()
\r
672 Directory.GetLastWriteTimeUtc (Path.InvalidPathChars[0].ToString ());
\r
676 public void Move_DestDirName_Empty ()
\r
679 Directory.Move (TempFolder, string.Empty);
\r
680 Assert.Fail ("#A1");
\r
681 } catch (ArgumentException ex) {
\r
682 // Empty file name is not legal
\r
683 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
684 Assert.IsNull (ex.InnerException, "#A3");
\r
685 Assert.IsNotNull (ex.Message, "#A4");
\r
686 Assert.IsNotNull (ex.ParamName, "#A5");
\r
687 Assert.AreEqual ("destDirName", ex.ParamName, "#A6");
\r
691 Directory.Move (TempFolder, " ");
\r
692 Assert.Fail ("#B1");
\r
693 } catch (ArgumentException ex) {
\r
694 // The path is not of a legal form
\r
695 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
696 Assert.IsNull (ex.InnerException, "#B3");
\r
697 Assert.IsNotNull (ex.Message, "#B4");
\r
702 public void Move_DestDirName_Null ()
\r
705 Directory.Move (TempFolder, (string) null);
\r
706 Assert.Fail ("#1");
\r
707 } catch (ArgumentNullException ex) {
\r
708 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
709 Assert.IsNull (ex.InnerException, "#3");
\r
710 Assert.IsNotNull (ex.Message, "#4");
\r
711 Assert.IsNotNull (ex.ParamName, "#5");
\r
712 Assert.AreEqual ("destDirName", ex.ParamName, "#6");
\r
717 public void Move_SourceDirName_Empty ()
\r
720 Directory.Move (string.Empty, TempFolder);
\r
721 Assert.Fail ("#A1");
\r
722 } catch (ArgumentException ex) {
\r
723 // Empty file name is not legal
\r
724 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
725 Assert.IsNull (ex.InnerException, "#A3");
\r
726 Assert.IsNotNull (ex.Message, "#A4");
\r
727 Assert.IsNotNull (ex.ParamName, "#A5");
\r
728 Assert.AreEqual ("sourceDirName", ex.ParamName, "#A6");
\r
732 Directory.Move (" ", TempFolder);
\r
733 Assert.Fail ("#B1");
\r
734 } catch (ArgumentException ex) {
\r
735 // The path is not of a legal form
\r
736 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
737 Assert.IsNull (ex.InnerException, "#B3");
\r
738 Assert.IsNotNull (ex.Message, "#B4");
\r
743 public void Move_SourceDirName_Null ()
\r
746 Directory.Move ((string) null, TempFolder);
\r
747 Assert.Fail ("#1");
\r
748 } catch (ArgumentNullException ex) {
\r
749 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
750 Assert.IsNull (ex.InnerException, "#3");
\r
751 Assert.IsNotNull (ex.Message, "#4");
\r
752 Assert.IsNotNull (ex.ParamName, "#5");
\r
753 Assert.AreEqual ("sourceDirName", ex.ParamName, "#6");
\r
758 public void MoveDirectory ()
\r
760 string path = TempFolder + DSC + "DirectoryTest.Test.9";
\r
761 string path2 = TempFolder + DSC + "DirectoryTest.Test.10";
\r
762 DeleteDirectory (path);
\r
763 DeleteDirectory (path2);
\r
765 Directory.CreateDirectory (path);
\r
766 Directory.CreateDirectory (path + DSC + "dir");
\r
767 Assert.IsTrue (Directory.Exists (path + DSC + "dir"), "#1");
\r
769 Directory.Move (path, path2);
\r
770 Assert.IsFalse (Directory.Exists (path + DSC + "dir"), "#2");
\r
771 Assert.IsTrue (Directory.Exists (path2 + DSC + "dir"), "#3");
\r
773 DeleteDirectory (path);
\r
774 DeleteDirectory (path2);
\r
775 if (Directory.Exists (path2 + DSC + "dir"))
\r
776 Directory.Delete (path2 + DSC + "dir", true);
\r
781 [ExpectedException (typeof (IOException))]
\r
782 public void MoveDirectory_Same ()
\r
784 string path = TempFolder + DSC + "DirectoryTest.Test.8";
\r
785 DeleteDirectory (path);
\r
787 Directory.Move (path, path);
\r
789 DeleteDirectory (path);
\r
794 public void MoveFile ()
\r
796 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
797 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
799 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
800 sw.Write ("temp1");
\r
802 Assert.IsFalse (File.Exists (tempFile2), "#1");
\r
803 Directory.Move (tempFile1, tempFile2);
\r
804 Assert.IsFalse (File.Exists (tempFile1), "#2");
\r
805 Assert.IsTrue (File.Exists (tempFile2), "#3");
\r
806 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
807 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#4");
\r
812 public void MoveFile_DestDir_Exists ()
\r
814 string tempFile = Path.Combine (TempFolder, "temp1.txt");
\r
815 string tempDir = Path.Combine (TempFolder, "temp2");
\r
817 using (StreamWriter sw = File.CreateText (tempFile)) {
\r
818 sw.Write ("temp1");
\r
820 Directory.CreateDirectory (tempDir);
\r
823 Directory.Move (tempFile, tempDir);
\r
824 Assert.Fail ("#A1");
\r
825 } catch (IOException ex) {
\r
826 // Cannot create a file when that file already exists
\r
827 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
828 Assert.IsNull (ex.InnerException, "#A3");
\r
829 Assert.IsNotNull (ex.Message, "#A4");
\r
832 Assert.IsTrue (File.Exists (tempFile), "#B1");
\r
833 Assert.IsFalse (File.Exists (tempDir), "#B2");
\r
834 Assert.IsTrue (Directory.Exists (tempDir), "#B3");
\r
838 public void MoveFile_DestFile_Exists ()
\r
840 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
841 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
843 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
844 sw.Write ("temp1");
\r
846 using (StreamWriter sw = File.CreateText (tempFile2)) {
\r
847 sw.Write ("temp2");
\r
851 Directory.Move (tempFile1, tempFile2);
\r
852 Assert.Fail ("#A1");
\r
853 } catch (IOException ex) {
\r
854 // Cannot create a file when that file already exists
\r
855 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
856 Assert.IsNull (ex.InnerException, "#A3");
\r
857 Assert.IsNotNull (ex.Message, "#A4");
\r
860 Assert.IsTrue (File.Exists (tempFile1), "#B1");
\r
861 using (StreamReader sr = File.OpenText (tempFile1)) {
\r
862 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#B2");
\r
865 Assert.IsTrue (File.Exists (tempFile2), "#C1");
\r
866 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
867 Assert.AreEqual ("temp2", sr.ReadToEnd (), "#C2");
\r
872 public void MoveFile_Same ()
\r
874 string tempFile = Path.Combine (TempFolder, "temp.txt");
\r
877 Directory.Move (tempFile, tempFile);
\r
878 Assert.Fail ("#1");
\r
879 } catch (IOException ex) {
\r
880 // Source and destination path must be different
\r
881 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
882 Assert.IsNull (ex.InnerException, "#3");
\r
883 Assert.IsNotNull (ex.Message, "#4");
\r
888 [ExpectedException(typeof(ArgumentException))]
\r
889 [Ignore ("On IA64, causes nunit to abort due to bug #76388")]
\r
890 public void MoveException4 ()
\r
892 string path = TempFolder + DSC + "DirectoryTest.Test.13";
\r
893 path += Path.InvalidPathChars [0];
\r
894 string path2 = TempFolder + DSC + "DirectoryTest.Test.13";
\r
895 DeleteDirectory (path);
\r
896 DeleteDirectory (path2);
\r
898 Directory.CreateDirectory (path2);
\r
899 Directory.Move (path2, path);
\r
901 DeleteDirectory (path);
\r
902 DeleteDirectory (path2);
\r
907 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
908 public void MoveException5 ()
\r
910 string path = TempFolder + DSC + "DirectoryTest.Test.14";
\r
911 DeleteDirectory (path);
\r
913 Directory.Move (path, path + "Test.Test");
\r
915 DeleteDirectory (path);
\r
916 DeleteDirectory (path + "Test.Test");
\r
921 [ExpectedException(typeof(IOException))]
\r
922 public void MoveDirectory_Dest_SubDir ()
\r
924 string path = TempFolder + DSC + "DirectoryTest.Test.15";
\r
925 DeleteDirectory (path);
\r
927 Directory.CreateDirectory (path);
\r
928 Directory.Move (path, path + DSC + "dir");
\r
930 DeleteDirectory (path);
\r
931 DeleteDirectory (path + DSC + "dir");
\r
936 [ExpectedException (typeof (IOException))]
\r
937 public void MoveDirectory_Dest_Exists ()
\r
939 string path = TempFolder + DSC + "DirectoryTest.Test.16";
\r
940 string path2 = TempFolder + DSC + "DirectoryTest.Test.17";
\r
942 DeleteDirectory (path);
\r
943 DeleteDirectory (path2);
\r
945 Directory.CreateDirectory (path);
\r
946 Directory.CreateDirectory (path2);
\r
947 Directory.Move (path, path2);
\r
949 DeleteDirectory (path);
\r
950 DeleteDirectory (path2);
\r
955 [Category("TargetJvmNotSupported")] // CreationTime not supported for TARGET_JVM
\r
956 public void CreationTime ()
\r
959 Assert.Ignore ("Unix doesn't support CreationTime");
\r
961 string path = TempFolder + DSC + "DirectoryTest.CreationTime.1";
\r
962 DeleteDirectory (path);
\r
965 Directory.CreateDirectory (path);
\r
966 Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
968 DateTime time = Directory.GetCreationTime (path);
\r
969 Assert.AreEqual (2003, time.Year, "#A1");
\r
970 Assert.AreEqual (6, time.Month, "#A2");
\r
971 Assert.AreEqual (4, time.Day, "#A3");
\r
972 Assert.AreEqual (6, time.Hour, "#A4");
\r
973 Assert.AreEqual (4, time.Minute, "#A5");
\r
974 Assert.AreEqual (0, time.Second, "#A6");
\r
976 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
\r
977 Assert.AreEqual (2003, time.Year, "#B1");
\r
978 Assert.AreEqual (6, time.Month, "#B2");
\r
979 Assert.AreEqual (4, time.Day, "#B3");
\r
980 Assert.AreEqual (6, time.Hour, "#B4");
\r
981 Assert.AreEqual (4, time.Minute, "#B5");
\r
982 Assert.AreEqual (0, time.Second, "#B6");
\r
984 Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
985 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
\r
986 Assert.AreEqual (2003, time.Year, "#C1");
\r
987 Assert.AreEqual (6, time.Month, "#C2");
\r
988 Assert.AreEqual (4, time.Day, "#C3");
\r
989 Assert.AreEqual (6, time.Hour, "#C4");
\r
990 Assert.AreEqual (4, time.Minute, "#C5");
\r
991 Assert.AreEqual (0, time.Second, "#C6");
\r
993 time = Directory.GetCreationTimeUtc (path);
\r
994 Assert.AreEqual (2003, time.Year, "#D1");
\r
995 Assert.AreEqual (6, time.Month, "#D2");
\r
996 Assert.AreEqual (4, time.Day, "#D3");
\r
997 Assert.AreEqual (6, time.Hour, "#D4");
\r
998 Assert.AreEqual (4, time.Minute, "#D5");
\r
999 Assert.AreEqual (0, time.Second, "#D6");
\r
1001 DeleteDirectory (path);
\r
1006 [Category("TargetJvmNotSupported")] // LastAccessTime not supported for TARGET_JVM
\r
1007 public void LastAccessTime ()
\r
1009 string path = TempFolder + DSC + "DirectoryTest.AccessTime.1";
\r
1010 DeleteDirectory (path);
\r
1013 Directory.CreateDirectory (path);
\r
1014 Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1016 DateTime time = Directory.GetLastAccessTime (path);
\r
1017 Assert.AreEqual (2003, time.Year, "#A1");
\r
1018 Assert.AreEqual (6, time.Month, "#A2");
\r
1019 Assert.AreEqual (4, time.Day, "#A3");
\r
1020 Assert.AreEqual (6, time.Hour, "#A4");
\r
1021 Assert.AreEqual (4, time.Minute, "#A5");
\r
1022 Assert.AreEqual (0, time.Second, "#A6");
\r
1024 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
\r
1025 Assert.AreEqual (2003, time.Year, "#B1");
\r
1026 Assert.AreEqual (6, time.Month, "#B2");
\r
1027 Assert.AreEqual (4, time.Day, "#B3");
\r
1028 Assert.AreEqual (6, time.Hour, "#B4");
\r
1029 Assert.AreEqual (4, time.Minute, "#B5");
\r
1030 Assert.AreEqual (0, time.Second, "#B6");
\r
1032 Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1033 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
\r
1034 Assert.AreEqual (2003, time.Year, "#C1");
\r
1035 Assert.AreEqual (6, time.Month, "#C2");
\r
1036 Assert.AreEqual (4, time.Day, "#C3");
\r
1037 Assert.AreEqual (6, time.Hour, "#C4");
\r
1038 Assert.AreEqual (4, time.Minute, "#C5");
\r
1039 Assert.AreEqual (0, time.Second, "#C6");
\r
1041 time = Directory.GetLastAccessTimeUtc (path);
\r
1042 Assert.AreEqual (2003, time.Year, "#D1");
\r
1043 Assert.AreEqual (6, time.Month, "#D2");
\r
1044 Assert.AreEqual (4, time.Day, "#D3");
\r
1045 Assert.AreEqual (6, time.Hour, "#D4");
\r
1046 Assert.AreEqual (4, time.Minute, "#D5");
\r
1047 Assert.AreEqual (0, time.Second, "#D6");
\r
1049 DeleteDirectory (path);
\r
1054 public void LastWriteTime ()
\r
1056 string path = TempFolder + DSC + "DirectoryTest.WriteTime.1";
\r
1057 DeleteDirectory (path);
\r
1060 Directory.CreateDirectory (path);
\r
1061 Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1063 DateTime time = Directory.GetLastWriteTime (path);
\r
1064 Assert.AreEqual (2003, time.Year, "#A1");
\r
1065 Assert.AreEqual (6, time.Month, "#A2");
\r
1066 Assert.AreEqual (4, time.Day, "#A3");
\r
1067 Assert.AreEqual (6, time.Hour, "#A4");
\r
1068 Assert.AreEqual (4, time.Minute, "#A5");
\r
1069 Assert.AreEqual (0, time.Second, "#A6");
\r
1071 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
\r
1072 Assert.AreEqual (2003, time.Year, "#B1");
\r
1073 Assert.AreEqual (6, time.Month, "#B2");
\r
1074 Assert.AreEqual (4, time.Day, "#B3");
\r
1075 Assert.AreEqual (6, time.Hour, "#B4");
\r
1076 Assert.AreEqual (4, time.Minute, "#B5");
\r
1077 Assert.AreEqual (0, time.Second, "#B6");
\r
1079 Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1080 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
\r
1081 Assert.AreEqual (2003, time.Year, "#C1");
\r
1082 Assert.AreEqual (6, time.Month, "#C2");
\r
1083 Assert.AreEqual (4, time.Day, "#C3");
\r
1084 Assert.AreEqual (6, time.Hour, "#C4");
\r
1085 Assert.AreEqual (4, time.Minute, "#C5");
\r
1086 Assert.AreEqual (0, time.Second, "#C6");
\r
1088 time = Directory.GetLastWriteTimeUtc (path);
\r
1089 Assert.AreEqual (2003, time.Year, "#D1");
\r
1090 Assert.AreEqual (6, time.Month, "#D2");
\r
1091 Assert.AreEqual (4, time.Day, "#D3");
\r
1092 Assert.AreEqual (6, time.Hour, "#D4");
\r
1093 Assert.AreEqual (4, time.Minute, "#D5");
\r
1094 Assert.AreEqual (0, time.Second, "#D6");
\r
1096 DeleteDirectory (path);
\r
1101 [ExpectedException(typeof(ArgumentNullException))]
\r
1102 public void SetLastWriteTimeException1 ()
\r
1104 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1105 Directory.SetLastWriteTime (null as string, time);
\r
1109 [ExpectedException(typeof(ArgumentException))]
\r
1110 public void SetLastWriteTimeException2 ()
\r
1112 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1113 Directory.SetLastWriteTime (string.Empty, time);
\r
1117 [ExpectedException(typeof(FileNotFoundException))]
\r
1118 public void SetLastWriteTimeException3 ()
\r
1120 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1121 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTime.2";
\r
1122 DeleteDirectory (path);
\r
1124 Directory.SetLastWriteTime (path, time);
\r
1126 DeleteDirectory (path);
\r
1131 [ExpectedException(typeof(ArgumentException))]
\r
1132 public void SetLastWriteTimeException4 ()
\r
1134 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1135 Directory.SetLastWriteTime (" ", time);
\r
1139 [ExpectedException(typeof(ArgumentException))]
\r
1140 public void SetLastWriteTimeException5 ()
\r
1142 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1143 Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
\r
1147 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1148 // public void SetLastWriteTimeException6 ()
\r
1150 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1151 // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
\r
1154 // if (!Directory.Exists (path))
\r
1155 // Directory.CreateDirectory (path);
\r
1157 // Directory.SetLastWriteTime (path, time);
\r
1159 // DeleteDirectory (path);
\r
1165 [ExpectedException(typeof(ArgumentNullException))]
\r
1166 public void SetLastWriteTimeUtcException1 ()
\r
1168 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1169 Directory.SetLastWriteTimeUtc (null as string, time);
\r
1173 [ExpectedException(typeof(ArgumentException))]
\r
1174 public void SetLastWriteTimeUtcException2 ()
\r
1176 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1177 Directory.SetLastWriteTimeUtc (string.Empty, time);
\r
1181 [ExpectedException(typeof(FileNotFoundException))]
\r
1182 public void SetLastWriteTimeUtcException3 ()
\r
1184 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1185 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.2";
\r
1186 DeleteDirectory (path);
\r
1188 Directory.SetLastWriteTimeUtc (path, time);
\r
1190 DeleteDirectory (path);
\r
1195 [ExpectedException(typeof(ArgumentException))]
\r
1196 public void SetLastWriteTimeUtcException4 ()
\r
1198 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1199 Directory.SetLastWriteTimeUtc (" ", time);
\r
1203 [ExpectedException(typeof(ArgumentException))]
\r
1204 public void SetLastWriteTimeUtcException5 ()
\r
1206 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1207 Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1211 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1212 // public void SetLastWriteTimeUtcException6 ()
\r
1214 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1215 // string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.1";
\r
1217 // if (!Directory.Exists (path))
\r
1218 // Directory.CreateDirectory (path);
\r
1220 // Directory.SetLastWriteTimeUtc (path, time);
\r
1222 // DeleteDirectory (path);
\r
1227 [ExpectedException(typeof(ArgumentNullException))]
\r
1228 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1229 public void SetLastAccessTimeException1 ()
\r
1231 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1232 Directory.SetLastAccessTime (null as string, time);
\r
1236 [ExpectedException(typeof(ArgumentException))]
\r
1237 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1238 public void SetLastAccessTimeException2 ()
\r
1240 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1241 Directory.SetLastAccessTime (string.Empty, time);
\r
1245 [ExpectedException(typeof(FileNotFoundException))]
\r
1246 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1247 public void SetLastAccessTimeException3 ()
\r
1249 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1250 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.2";
\r
1251 DeleteDirectory (path);
\r
1253 Directory.SetLastAccessTime (path, time);
\r
1255 DeleteDirectory (path);
\r
1260 [ExpectedException(typeof(ArgumentException))]
\r
1261 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1262 public void SetLastAccessTimeException4 ()
\r
1264 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1265 Directory.SetLastAccessTime (" ", time);
\r
1269 [ExpectedException(typeof(ArgumentException))]
\r
1270 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1271 public void SetLastAccessTimeException5 ()
\r
1273 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1274 Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
\r
1278 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1279 // public void SetLastAccessTimeException6 ()
\r
1281 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1282 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.1";
\r
1284 // if (!Directory.Exists (path))
\r
1285 // Directory.CreateDirectory (path);
\r
1287 // Directory.SetLastAccessTime (path, time);
\r
1289 // DeleteDirectory (path);
\r
1295 [ExpectedException(typeof(ArgumentNullException))]
\r
1296 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1297 public void SetLastAccessTimeUtcException1 ()
\r
1299 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1300 Directory.SetLastAccessTimeUtc (null as string, time);
\r
1304 [ExpectedException(typeof(ArgumentException))]
\r
1305 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1306 public void SetLastAccessTimeUtcException2 ()
\r
1308 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1309 Directory.SetLastAccessTimeUtc (string.Empty, time);
\r
1313 [ExpectedException(typeof(FileNotFoundException))]
\r
1314 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1315 public void SetLastAccessTimeUtcException3 ()
\r
1317 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1318 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1319 DeleteDirectory (path);
\r
1321 Directory.SetLastAccessTimeUtc (path, time);
\r
1323 DeleteDirectory (path);
\r
1328 [ExpectedException(typeof(ArgumentException))]
\r
1329 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1330 public void SetLastAccessTimeUtcException4 ()
\r
1332 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1333 Directory.SetLastAccessTimeUtc (" ", time);
\r
1337 [ExpectedException(typeof(ArgumentException))]
\r
1338 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1339 public void SetLastAccessTimeUtcException5 ()
\r
1341 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1342 Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1346 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1347 // public void SetLastAccessTimeUtcException6 ()
\r
1349 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1350 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1352 // if (!Directory.Exists (path))
\r
1353 // Directory.CreateDirectory (path);
\r
1355 // Directory.SetLastAccessTimeUtc (path, time);
\r
1357 // DeleteDirectory (path);
\r
1362 [ExpectedException(typeof(ArgumentNullException))]
\r
1363 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1364 public void SetCreationTimeException1 ()
\r
1366 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1367 Directory.SetCreationTime (null as string, time);
\r
1371 [ExpectedException(typeof(ArgumentException))]
\r
1372 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1373 public void SetCreationTimeException2 ()
\r
1375 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1376 Directory.SetCreationTime (string.Empty, time);
\r
1380 [ExpectedException(typeof(FileNotFoundException))]
\r
1381 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1382 public void SetCreationTimeException3 ()
\r
1384 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1385 string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.2";
\r
1386 DeleteDirectory (path);
\r
1389 Directory.SetCreationTime (path, time);
\r
1391 DeleteDirectory (path);
\r
1396 [ExpectedException(typeof(ArgumentException))]
\r
1397 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1398 public void SetCreationTimeException4 ()
\r
1400 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1401 Directory.SetCreationTime (" ", time);
\r
1405 [ExpectedException(typeof(ArgumentException))]
\r
1406 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1407 public void SetCreationTimeException5 ()
\r
1409 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1410 Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
\r
1414 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1415 // public void SetCreationTimeException6 ()
\r
1417 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1418 // string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.1";
\r
1420 // if (!Directory.Exists (path))
\r
1421 // Directory.CreateDirectory (path);
\r
1423 // Directory.SetCreationTime (path, time);
\r
1424 // DeleteDirectory (path);
\r
1426 // DeleteDirectory (path);
\r
1432 [ExpectedException(typeof(ArgumentNullException))]
\r
1433 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1434 public void SetCreationTimeUtcException1 ()
\r
1436 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1437 Directory.SetCreationTimeUtc (null as string, time);
\r
1441 [ExpectedException(typeof(ArgumentException))]
\r
1442 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1443 public void SetCreationTimeUtcException2 ()
\r
1445 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1446 Directory.SetCreationTimeUtc (string.Empty, time);
\r
1450 [ExpectedException(typeof(FileNotFoundException))]
\r
1451 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1452 public void SetCreationTimeUtcException3 ()
\r
1454 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1455 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1456 DeleteDirectory (path);
\r
1459 Directory.SetCreationTimeUtc (path, time);
\r
1460 DeleteDirectory (path);
\r
1462 DeleteDirectory (path);
\r
1467 [ExpectedException(typeof(ArgumentException))]
\r
1468 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1469 public void SetCreationTimeUtcException4 ()
\r
1471 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1472 Directory.SetCreationTimeUtc (" ", time);
\r
1476 [ExpectedException(typeof(ArgumentException))]
\r
1477 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1478 public void SetCreationTimeUtcException5 ()
\r
1480 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1481 Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1485 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1486 // public void SetCreationTimeUtcException6 ()
\r
1488 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1489 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1491 // if (!Directory.Exists (path))
\r
1492 // Directory.CreateDirectory (path);
\r
1494 // Directory.SetCreationTimeUtc (path, time);
\r
1495 // DeleteDirectory (path);
\r
1497 // DeleteDirectory (path);
\r
1502 public void GetDirectories ()
\r
1504 string path = TempFolder;
\r
1505 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetDirectories";
\r
1506 DeleteDirectory (DirPath);
\r
1509 Directory.CreateDirectory (DirPath);
\r
1511 string [] dirs = Directory.GetDirectories (path);
\r
1513 foreach (string directory in dirs) {
\r
1515 if (directory == DirPath)
\r
1519 Assert.Fail ("Directory Not Found");
\r
1521 DeleteDirectory (DirPath);
\r
1525 [Test] // bug #346123
\r
1526 public void GetDirectories_Backslash ()
\r
1528 if (!RunningOnUnix)
\r
1529 // on Windows, backslash is used as directory separator
\r
1532 string dir = Path.Combine (TempFolder, @"sub\dir");
\r
1533 Directory.CreateDirectory (dir);
\r
1535 Assert.IsTrue (Directory.Exists (dir), "#A1");
\r
1536 Assert.IsFalse (Directory.Exists (Path.Combine (TempFolder, "dir")), "#A2");
\r
1538 string [] dirs = Directory.GetDirectories (TempFolder);
\r
1539 Assert.AreEqual (1, dirs.Length, "#B1");
\r
1540 Assert.AreEqual (dir, dirs [0], "#B2");
\r
1544 public void GetParentOfRootDirectory ()
\r
1546 DirectoryInfo info;
\r
1548 info = Directory.GetParent (Path.GetPathRoot (Path.GetTempPath ()));
\r
1549 Assert.IsNull (info);
\r
1553 public void GetFiles ()
\r
1555 string path = TempFolder;
\r
1556 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetFiles";
\r
1557 if (File.Exists (DirPath))
\r
1558 File.Delete (DirPath);
\r
1561 File.Create (DirPath).Close ();
\r
1562 string [] files = Directory.GetFiles (TempFolder);
\r
1563 foreach (string directory in files) {
\r
1565 if (directory == DirPath)
\r
1569 Assert.Fail ("File Not Found");
\r
1571 if (File.Exists (DirPath))
\r
1572 File.Delete (DirPath);
\r
1576 [Test] // bug #346123
\r
1577 public void GetFiles_Backslash ()
\r
1579 if (!RunningOnUnix)
\r
1580 // on Windows, backslash is used as directory separator
\r
1583 string file = Path.Combine (TempFolder, @"doc\temp1.file");
\r
1584 File.Create (file).Close ();
\r
1586 Assert.IsTrue (File.Exists (file), "#A1");
\r
1587 Assert.IsFalse (File.Exists (Path.Combine (TempFolder, "temp1.file")), "#A2");
\r
1589 string [] files = Directory.GetFiles (TempFolder);
\r
1590 Assert.AreEqual (1, files.Length, "#B1");
\r
1591 Assert.AreEqual (file, files [0], "#B2");
\r
1594 [Test] // bug #82212 and bug #325107
\r
1595 public void GetFiles_Pattern ()
\r
1597 string [] files = Directory.GetFiles (TempFolder, "*.*");
\r
1598 Assert.IsNotNull (files, "#A1");
\r
1599 Assert.AreEqual (0, files.Length, "#A2");
\r
1601 string tempFile1 = Path.Combine (TempFolder, "tempFile1");
\r
1602 File.Create (tempFile1).Close ();
\r
1604 files = Directory.GetFiles (TempFolder, "*.*");
\r
1605 Assert.IsNotNull (files, "#B1");
\r
1606 Assert.AreEqual (1, files.Length, "#B2");
\r
1607 Assert.AreEqual (tempFile1, files [0], "#B3");
\r
1609 string tempFile2 = Path.Combine (TempFolder, "FileTemp2.tmp");
\r
1610 File.Create (tempFile2).Close ();
\r
1612 files = Directory.GetFiles (TempFolder, "*.*");
\r
1613 Assert.IsNotNull (files, "#C1");
\r
1614 Assert.AreEqual (2, files.Length, "#C2");
\r
1616 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1617 Assert.IsNotNull (files, "#D1");
\r
1618 Assert.AreEqual (1, files.Length, "#D2");
\r
1619 Assert.AreEqual (tempFile1, files [0], "#D3");
\r
1621 string tempFile3 = Path.Combine (TempFolder, "tempFile3.txt");
\r
1622 File.Create (tempFile3).Close ();
\r
1624 files = Directory.GetFiles (TempFolder, "*File*.*");
\r
1625 Assert.IsNotNull (files, "#E1");
\r
1626 Assert.AreEqual (3, files.Length, "#E2");
\r
1628 files = Directory.GetFiles (TempFolder, "*File*.tmp");
\r
1629 Assert.IsNotNull (files, "#F1");
\r
1630 Assert.AreEqual (1, files.Length, "#F2");
\r
1631 Assert.AreEqual (tempFile2, files [0], "#F3");
\r
1633 files = Directory.GetFiles (TempFolder, "*tempFile*");
\r
1634 Assert.IsNotNull (files, "#G1");
\r
1635 Assert.AreEqual (2, files.Length, "#G2");
\r
1637 files = Directory.GetFiles (TempFolder, "*tempFile1");
\r
1638 Assert.IsNotNull (files, "#H1");
\r
1639 Assert.AreEqual (1, files.Length, "#H2");
\r
1640 Assert.AreEqual (tempFile1, files [0], "#H3");
\r
1642 files = Directory.GetFiles (TempFolder, "*.txt");
\r
1643 Assert.IsNotNull (files, "#I1");
\r
1644 Assert.AreEqual (1, files.Length, "#I2");
\r
1645 Assert.AreEqual (tempFile3, files [0], "#I3");
\r
1647 files = Directory.GetFiles (TempFolder, "*.t*");
\r
1648 Assert.IsNotNull (files, "#J1");
\r
1649 Assert.AreEqual (2, files.Length, "#J2");
\r
1651 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1652 Assert.IsNotNull (files, "#K1");
\r
1653 Assert.AreEqual (2, files.Length, "#K2");
\r
1655 File.Delete (tempFile1);
\r
1657 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1658 Assert.IsNotNull (files, "#L1");
\r
1659 Assert.AreEqual (1, files.Length, "#L2");
\r
1660 Assert.AreEqual (tempFile3, files [0], "#L3");
\r
1662 files = Directory.GetFiles (TempFolder, ".*");
\r
1663 Assert.IsNotNull (files, "#M1");
\r
1664 Assert.AreEqual (0, files.Length, "#M2");
\r
1666 string tempFile4 = Path.Combine (TempFolder, "tempFile4.");
\r
1667 File.Create (tempFile4).Close ();
\r
1669 files = Directory.GetFiles (TempFolder, "temp*.");
\r
1670 Assert.IsNotNull (files, "#N1");
\r
1671 Assert.AreEqual (1, files.Length, "#N2");
\r
1672 if (RunningOnUnix)
\r
1673 Assert.AreEqual (tempFile4, files [0], "#N3");
\r
1674 else // on Windows, the trailing dot is automatically trimmed
\r
1675 Assert.AreEqual (Path.Combine (TempFolder, "tempFile4"), files [0], "#N3");
\r
1679 public void GetFiles_580090 ()
\r
1681 string cwd = Directory.GetCurrentDirectory ();
\r
1682 Directory.SetCurrentDirectory (Path.GetTempPath ());
\r
1684 string tempFile = Path.Combine (TempFolder, "tempFile.txt");
\r
1685 File.Create (tempFile).Close ();
\r
1688 string [] files = Directory.GetFiles (".", TempSubFolder + DSC + "*.t*");
\r
1689 Assert.IsNotNull (files, "#J1");
\r
1690 Assert.AreEqual (1, files.Length, "#J2");
\r
1693 Directory.SetCurrentDirectory (cwd);
\r
1699 [ExpectedException (typeof (ArgumentNullException))]
\r
1700 public void SetCurrentDirectoryNull ()
\r
1702 Directory.SetCurrentDirectory (null);
\r
1706 [ExpectedException (typeof (ArgumentException))]
\r
1707 public void SetCurrentDirectoryEmpty ()
\r
1709 Directory.SetCurrentDirectory (String.Empty);
\r
1713 [ExpectedException (typeof (ArgumentException))]
\r
1714 public void SetCurrentDirectoryWhitespace ()
\r
1716 Directory.SetCurrentDirectory (" ");
\r
1721 public void GetNoFiles () // Bug 58875. This throwed an exception on windows.
\r
1723 DirectoryInfo dir = new DirectoryInfo (".");
\r
1724 dir.GetFiles ("*.nonext");
\r
1728 public void FilenameOnly () // bug 78209
\r
1730 Directory.GetParent ("somefile");
\r
1733 private static bool RunningOnUnix {
\r
1735 // check for Unix platforms - see FAQ for more details
\r
1736 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
\r
1737 int platform = (int) Environment.OSVersion.Platform;
\r
1738 return ((platform == 4) || (platform == 128) || (platform == 6));
\r
1742 private void DeleteDirectory (string path)
\r
1744 if (Directory.Exists (path))
\r
1745 Directory.Delete (path, true);
\r
1748 private void DeleteFile (string path)
\r
1750 if (File.Exists (path))
\r
1751 File.Delete (path);
\r