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
41 if (Directory.Exists (TempFolder))
\r
42 Directory.Delete (TempFolder, true);
\r
46 public void CreateDirectory ()
\r
48 string path = TempFolder + DSC + "DirectoryTest.Test.1";
\r
49 DeleteDirectory (path);
\r
51 DirectoryInfo info = Directory.CreateDirectory (path);
\r
52 Assert.IsTrue (info.Exists, "#1");
\r
53 Assert.AreEqual (".1", info.Extension, "#2");
\r
54 Assert.IsTrue (info.FullName.EndsWith ("DirectoryTest.Test.1"), "#3");
\r
55 Assert.AreEqual ("DirectoryTest.Test.1", info.Name, "#4");
\r
57 DeleteDirectory (path);
\r
62 public void CreateDirectoryNotSupportedException ()
\r
64 DeleteDirectory (":");
\r
66 DirectoryInfo info = Directory.CreateDirectory (":");
\r
68 } catch (ArgumentException) {
\r
70 DeleteDirectory (":");
\r
74 [ExpectedException(typeof(ArgumentNullException))]
\r
75 public void CreateDirectoryArgumentNullException ()
\r
77 DirectoryInfo info = Directory.CreateDirectory (null as string);
\r
81 [ExpectedException(typeof(ArgumentException))]
\r
82 public void CreateDirectoryArgumentException1 ()
\r
84 DirectoryInfo info = Directory.CreateDirectory ("");
\r
88 [ExpectedException(typeof(ArgumentException))]
\r
89 public void CreateDirectoryArgumentException2 ()
\r
91 DirectoryInfo info = Directory.CreateDirectory (" ");
\r
95 [ExpectedException(typeof(ArgumentException))]
\r
96 public void CreateDirectoryArgumentException3 ()
\r
98 string path = TempFolder + DSC + "DirectoryTest.Test";
\r
99 DeleteDirectory (path);
\r
103 DirectoryInfo info = Directory.CreateDirectory (path);
\r
105 DeleteDirectory (path);
\r
110 public void CreateDirectoryAlreadyExists ()
\r
112 string path = TempFolder + DSC + "DirectoryTest.Test.Exists";
\r
113 DeleteDirectory (path);
\r
115 DirectoryInfo info1 = Directory.CreateDirectory (path);
\r
116 DirectoryInfo info2 = Directory.CreateDirectory (path);
\r
118 Assert.IsTrue (info2.Exists, "#1");
\r
119 Assert.IsTrue (info2.FullName.EndsWith ("DirectoryTest.Test.Exists"), "#2");
\r
120 Assert.AreEqual ("DirectoryTest.Test.Exists", info2.Name, "#3");
\r
122 DeleteDirectory (path);
\r
127 public void CreateDirectoryAlreadyExistsAsFile ()
\r
129 string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";
\r
130 DeleteDirectory (path);
\r
133 FileStream fstream = File.Create (path);
\r
136 DirectoryInfo dinfo = Directory.CreateDirectory (path);
\r
138 Assert.Fail ("#1");
\r
139 } catch (IOException ex) {
\r
140 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
141 Assert.IsNotNull (ex.Message, "#3");
\r
142 Assert.IsNull (ex.InnerException, "#4");
\r
144 Assert.IsFalse (dinfo.Exists, "#2");
\r
145 Assert.IsTrue (dinfo.FullName.EndsWith ("DirectoryTest.Test.ExistsAsFile"), "#3");
\r
146 Assert.AreEqual ("DirectoryTest.Test.ExistsAsFile", dinfo.Name, "#4");
\r
149 DeleteDirectory (path);
\r
155 public void Delete ()
\r
157 string path = TempFolder + DSC + "DirectoryTest.Test.Delete.1";
\r
158 DeleteDirectory (path);
\r
160 Directory.CreateDirectory (path);
\r
161 Assert.IsTrue (Directory.Exists (path), "#1");
\r
163 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
164 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#2");
\r
166 Directory.Delete (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
167 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#3");
\r
168 Assert.IsTrue (Directory.Exists (path), "#4");
\r
170 Directory.Delete (path);
\r
171 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#5");
\r
172 Assert.IsFalse (Directory.Exists (path), "#6");
\r
174 Directory.CreateDirectory (path);
\r
175 Directory.CreateDirectory (path + DSC + "DirectoryTest.Test.Delete.1.2");
\r
176 Assert.IsTrue (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#7");
\r
177 Assert.IsTrue (Directory.Exists (path), "#8");
\r
179 Directory.Delete (path, true);
\r
180 Assert.IsFalse (Directory.Exists (path + DSC + "DirectoryTest.Test.Delete.1.2"), "#9");
\r
181 Assert.IsFalse (Directory.Exists (path), "#10");
\r
183 DeleteDirectory (path);
\r
188 [ExpectedException(typeof(ArgumentException))]
\r
189 public void DeleteArgumentException ()
\r
191 Directory.Delete ("");
\r
195 [ExpectedException(typeof(ArgumentException))]
\r
196 public void DeleteArgumentException2 ()
\r
198 Directory.Delete (" ");
\r
202 [ExpectedException(typeof(ArgumentException))]
\r
203 public void DeleteArgumentException3 ()
\r
205 string path = TempFolder + DSC + "DirectoryTest.Test.4";
\r
206 DeleteDirectory (path);
\r
208 path += Path.InvalidPathChars [0];
\r
209 Directory.Delete (path);
\r
213 [ExpectedException(typeof(ArgumentNullException))]
\r
214 public void DeleteArgumentNullException ()
\r
216 Directory.Delete (null as string);
\r
220 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
221 public void DeleteDirectoryNotFoundException ()
\r
223 string path = TempFolder + DSC + "DirectoryTest.Test.5";
\r
224 DeleteDirectory (path);
\r
226 Directory.Delete (path);
\r
230 [ExpectedException(typeof(IOException))]
\r
231 public void DeleteArgumentException4 ()
\r
233 string path = TempFolder + DSC + "DirectoryTest.Test.6";
\r
234 DeleteDirectory (path);
\r
235 FileStream s = null;
\r
236 Directory.CreateDirectory (path);
\r
238 s = File.Create (path + DSC + "DirectoryTest.Test.6");
\r
239 Directory.Delete (path);
\r
243 DeleteDirectory (path);
\r
248 public void Exists ()
\r
250 Assert.IsFalse (Directory.Exists (null as string));
\r
253 #if !TARGET_JVM // We don't support yet the Process class.
\r
254 [Test] // bug #78239
\r
255 public void ExistsAccessDenied ()
\r
257 if (!RunningOnUnix)
\r
258 return; // this test does not work on Windows.
\r
260 string path = TempFolder + DSC + "ExistsAccessDenied";
\r
262 Directory.CreateDirectory (path);
\r
263 Process.Start ("/bin/chmod", "000 " + path).WaitForExit ();
\r
265 Assert.IsFalse (Directory.Exists(path + DSC + "b"));
\r
267 Process.Start ("/bin/chmod", "755 " + path).WaitForExit ();
\r
268 Directory.Delete (path);
\r
274 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
275 [ExpectedException(typeof(ArgumentNullException))]
\r
276 public void GetCreationTimeException1 ()
\r
278 Directory.GetCreationTime (null as string);
\r
282 [ExpectedException(typeof(ArgumentException))]
\r
283 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
284 public void GetCreationTimeException2 ()
\r
286 Directory.GetCreationTime ("");
\r
291 [ExpectedException(typeof(IOException))]
\r
293 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
294 public void GetCreationTimeException_NonExistingPath ()
\r
296 string path = TempFolder + DSC + "DirectoryTest.GetCreationTime.1";
\r
297 DeleteDirectory (path);
\r
299 DateTime time = Directory.GetCreationTime (path);
\r
302 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
303 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
304 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
305 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
306 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
307 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
308 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
311 DeleteDirectory (path);
\r
316 [ExpectedException(typeof(ArgumentException))]
\r
317 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
318 public void GetCreationTimeException4 ()
\r
320 Directory.GetCreationTime (" ");
\r
324 [ExpectedException(typeof(ArgumentException))]
\r
325 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
326 public void GetCreationTimeException5 ()
\r
328 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
332 [ExpectedException(typeof(ArgumentNullException))]
\r
333 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
334 public void GetCreationTimeUtcException1 ()
\r
336 Directory.GetCreationTimeUtc (null as string);
\r
340 [ExpectedException(typeof(ArgumentException))]
\r
341 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
342 public void GetCreationTimeUtcException2 ()
\r
344 Directory.GetCreationTimeUtc ("");
\r
349 [ExpectedException (typeof (IOException))]
\r
351 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
352 public void GetCreationTimeUtc_NonExistingPath ()
\r
354 string path = TempFolder + DSC + "DirectoryTest.GetCreationTimeUtc.1";
\r
355 DeleteDirectory (path);
\r
358 DateTime time = Directory.GetCreationTimeUtc (path);
\r
361 Assert.AreEqual (1601, time.Year, "#1");
\r
362 Assert.AreEqual (1, time.Month, "#2");
\r
363 Assert.AreEqual (1, time.Day, "#3");
\r
364 Assert.AreEqual (0, time.Hour, "#4");
\r
365 Assert.AreEqual (0, time.Second, "#5");
\r
366 Assert.AreEqual (0, time.Millisecond, "#6");
\r
369 DeleteDirectory (path);
\r
374 [ExpectedException(typeof(ArgumentException))]
\r
375 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
376 public void GetCreationTimeUtcException4 ()
\r
378 Directory.GetCreationTimeUtc (" ");
\r
382 [ExpectedException(typeof(ArgumentException))]
\r
383 [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
\r
384 public void GetCreationTimeUtcException5 ()
\r
386 Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());
\r
390 [ExpectedException(typeof(ArgumentNullException))]
\r
391 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
392 public void GetLastAccessTime_Null ()
\r
394 Directory.GetLastAccessTime (null as string);
\r
398 [ExpectedException(typeof(ArgumentException))]
\r
399 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
400 public void GetLastAccessTimeException2 ()
\r
402 Directory.GetLastAccessTime ("");
\r
407 [ExpectedException (typeof (IOException))]
\r
409 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
410 public void GetLastAccessTime_NonExistingPath ()
\r
412 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTime.1";
\r
413 DeleteDirectory (path);
\r
416 DateTime time = Directory.GetLastAccessTime (path);
\r
419 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
420 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
421 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
422 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
423 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
424 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
425 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
428 DeleteDirectory (path);
\r
433 [ExpectedException(typeof(ArgumentException))]
\r
434 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
435 public void GetLastAccessTimeException4 ()
\r
437 Directory.GetLastAccessTime (" ");
\r
441 [ExpectedException(typeof(ArgumentException))]
\r
442 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
443 public void GetLastAccessTimeException5 ()
\r
445 Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());
\r
449 [ExpectedException(typeof(ArgumentNullException))]
\r
450 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
451 public void GetLastAccessTimeUtc_Null ()
\r
453 Directory.GetLastAccessTimeUtc (null as string);
\r
457 [ExpectedException(typeof(ArgumentException))]
\r
458 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
459 public void GetLastAccessTimeUtcException2 ()
\r
461 Directory.GetLastAccessTimeUtc ("");
\r
466 [ExpectedException (typeof (IOException))]
\r
468 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
469 public void GetLastAccessTimeUtc_NonExistingPath ()
\r
471 string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTimeUtc.1";
\r
472 DeleteDirectory (path);
\r
474 DateTime time = Directory.GetLastAccessTimeUtc (path);
\r
477 Assert.AreEqual (1601, time.Year, "#1");
\r
478 Assert.AreEqual (1, time.Month, "#2");
\r
479 Assert.AreEqual (1, time.Day, "#3");
\r
480 Assert.AreEqual (0, time.Hour, "#4");
\r
481 Assert.AreEqual (0, time.Second, "#5");
\r
482 Assert.AreEqual (0, time.Millisecond, "#6");
\r
485 DeleteDirectory (path);
\r
490 [ExpectedException(typeof(ArgumentException))]
\r
491 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
492 public void GetLastAccessTimeUtcException4 ()
\r
494 Directory.GetLastAccessTimeUtc (" ");
\r
498 [ExpectedException(typeof(ArgumentException))]
\r
499 [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
\r
500 public void GetLastAccessTimeUtcException5 ()
\r
502 Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());
\r
506 [ExpectedException(typeof(ArgumentNullException))]
\r
507 public void GetLastWriteTimeException1 ()
\r
509 Directory.GetLastWriteTime (null as string);
\r
513 [ExpectedException(typeof(ArgumentException))]
\r
514 public void GetLastWriteTimeException2 ()
\r
516 Directory.GetLastWriteTime ("");
\r
521 [ExpectedException (typeof (IOException))]
\r
523 public void GetLastWriteTime_NonExistingPath ()
\r
525 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTime.1";
\r
526 DeleteDirectory (path);
\r
528 DateTime time = Directory.GetLastWriteTime (path);
\r
531 DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
\r
532 Assert.AreEqual (expectedTime.Year, time.Year, "#1");
\r
533 Assert.AreEqual (expectedTime.Month, time.Month, "#2");
\r
534 Assert.AreEqual (expectedTime.Day, time.Day, "#3");
\r
535 Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
\r
536 Assert.AreEqual (expectedTime.Second, time.Second, "#5");
\r
537 Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
\r
540 DeleteDirectory (path);
\r
545 [ExpectedException(typeof(ArgumentException))]
\r
546 public void GetLastWriteTimeException4 ()
\r
548 Directory.GetLastWriteTime (" ");
\r
552 [ExpectedException(typeof(ArgumentException))]
\r
553 public void GetLastWriteTimeException5 ()
\r
555 Directory.GetLastWriteTime (Path.InvalidPathChars [0].ToString ());
\r
559 [ExpectedException(typeof(ArgumentNullException))]
\r
560 public void GetLastWriteTimeUtcException1 ()
\r
562 Directory.GetLastWriteTimeUtc (null as string);
\r
566 [ExpectedException(typeof(ArgumentException))]
\r
567 public void GetLastWriteTimeUtcException2 ()
\r
569 Directory.GetLastWriteTimeUtc ("");
\r
574 [ExpectedException (typeof (IOException))]
\r
576 public void GetLastWriteTimeUtc_NonExistingPath ()
\r
578 string path = TempFolder + DSC + "DirectoryTest.GetLastWriteTimeUtc.1";
\r
579 DeleteDirectory (path);
\r
581 DateTime time = Directory.GetLastWriteTimeUtc (path);
\r
584 Assert.AreEqual (1601, time.Year, "#1");
\r
585 Assert.AreEqual (1, time.Month, "#2");
\r
586 Assert.AreEqual (1, time.Day, "#3");
\r
587 Assert.AreEqual (0, time.Hour, "#4");
\r
588 Assert.AreEqual (0, time.Second, "#5");
\r
589 Assert.AreEqual (0, time.Millisecond, "#6");
\r
592 DeleteDirectory (path);
\r
598 [ExpectedException(typeof(ArgumentException))]
\r
599 public void GetLastWriteTimeUtcException4 ()
\r
601 Directory.GetLastWriteTimeUtc (" ");
\r
605 [ExpectedException(typeof(ArgumentException))]
\r
606 public void GetLastWriteTimeUtcException5 ()
\r
608 Directory.GetLastWriteTimeUtc (Path.InvalidPathChars[0].ToString ());
\r
612 public void Move_DestDirName_Empty ()
\r
615 Directory.Move (TempFolder, string.Empty);
\r
616 Assert.Fail ("#A1");
\r
617 } catch (ArgumentException ex) {
\r
618 // Empty file name is not legal
\r
619 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
620 Assert.IsNull (ex.InnerException, "#A3");
\r
621 Assert.IsNotNull (ex.Message, "#A4");
\r
622 Assert.IsNotNull (ex.ParamName, "#A5");
\r
623 Assert.AreEqual ("destDirName", ex.ParamName, "#A6");
\r
627 Directory.Move (TempFolder, " ");
\r
628 Assert.Fail ("#B1");
\r
629 } catch (ArgumentException ex) {
\r
630 // The path is not of a legal form
\r
631 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
632 Assert.IsNull (ex.InnerException, "#B3");
\r
633 Assert.IsNotNull (ex.Message, "#B4");
\r
638 public void Move_DestDirName_Null ()
\r
641 Directory.Move (TempFolder, (string) null);
\r
642 Assert.Fail ("#1");
\r
643 } catch (ArgumentNullException ex) {
\r
644 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
645 Assert.IsNull (ex.InnerException, "#3");
\r
646 Assert.IsNotNull (ex.Message, "#4");
\r
647 Assert.IsNotNull (ex.ParamName, "#5");
\r
648 Assert.AreEqual ("destDirName", ex.ParamName, "#6");
\r
653 public void Move_SourceDirName_Empty ()
\r
656 Directory.Move (string.Empty, TempFolder);
\r
657 Assert.Fail ("#A1");
\r
658 } catch (ArgumentException ex) {
\r
659 // Empty file name is not legal
\r
660 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");
\r
661 Assert.IsNull (ex.InnerException, "#A3");
\r
662 Assert.IsNotNull (ex.Message, "#A4");
\r
663 Assert.IsNotNull (ex.ParamName, "#A5");
\r
664 Assert.AreEqual ("sourceDirName", ex.ParamName, "#A6");
\r
668 Directory.Move (" ", TempFolder);
\r
669 Assert.Fail ("#B1");
\r
670 } catch (ArgumentException ex) {
\r
671 // The path is not of a legal form
\r
672 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");
\r
673 Assert.IsNull (ex.InnerException, "#B3");
\r
674 Assert.IsNotNull (ex.Message, "#B4");
\r
679 public void Move_SourceDirName_Null ()
\r
682 Directory.Move ((string) null, TempFolder);
\r
683 Assert.Fail ("#1");
\r
684 } catch (ArgumentNullException ex) {
\r
685 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
\r
686 Assert.IsNull (ex.InnerException, "#3");
\r
687 Assert.IsNotNull (ex.Message, "#4");
\r
688 Assert.IsNotNull (ex.ParamName, "#5");
\r
689 Assert.AreEqual ("sourceDirName", ex.ParamName, "#6");
\r
694 public void MoveDirectory ()
\r
696 string path = TempFolder + DSC + "DirectoryTest.Test.9";
\r
697 string path2 = TempFolder + DSC + "DirectoryTest.Test.10";
\r
698 DeleteDirectory (path);
\r
699 DeleteDirectory (path2);
\r
701 Directory.CreateDirectory (path);
\r
702 Directory.CreateDirectory (path + DSC + "dir");
\r
703 Assert.IsTrue (Directory.Exists (path + DSC + "dir"), "#1");
\r
705 Directory.Move (path, path2);
\r
706 Assert.IsFalse (Directory.Exists (path + DSC + "dir"), "#2");
\r
707 Assert.IsTrue (Directory.Exists (path2 + DSC + "dir"), "#3");
\r
709 DeleteDirectory (path);
\r
710 DeleteDirectory (path2);
\r
711 if (Directory.Exists (path2 + DSC + "dir"))
\r
712 Directory.Delete (path2 + DSC + "dir", true);
\r
717 [ExpectedException (typeof (IOException))]
\r
718 public void MoveDirectory_Same ()
\r
720 string path = TempFolder + DSC + "DirectoryTest.Test.8";
\r
721 DeleteDirectory (path);
\r
723 Directory.Move (path, path);
\r
725 DeleteDirectory (path);
\r
730 public void MoveFile ()
\r
732 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
733 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
735 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
736 sw.Write ("temp1");
\r
738 Assert.IsFalse (File.Exists (tempFile2), "#1");
\r
739 Directory.Move (tempFile1, tempFile2);
\r
740 Assert.IsFalse (File.Exists (tempFile1), "#2");
\r
741 Assert.IsTrue (File.Exists (tempFile2), "#3");
\r
742 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
743 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#4");
\r
748 public void MoveFile_DestDir_Exists ()
\r
750 string tempFile = Path.Combine (TempFolder, "temp1.txt");
\r
751 string tempDir = Path.Combine (TempFolder, "temp2");
\r
753 using (StreamWriter sw = File.CreateText (tempFile)) {
\r
754 sw.Write ("temp1");
\r
756 Directory.CreateDirectory (tempDir);
\r
759 Directory.Move (tempFile, tempDir);
\r
760 Assert.Fail ("#A1");
\r
761 } catch (IOException ex) {
\r
762 // Cannot create a file when that file already exists
\r
763 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
764 Assert.IsNull (ex.InnerException, "#A3");
\r
765 Assert.IsNotNull (ex.Message, "#A4");
\r
768 Assert.IsTrue (File.Exists (tempFile), "#B1");
\r
769 Assert.IsFalse (File.Exists (tempDir), "#B2");
\r
770 Assert.IsTrue (Directory.Exists (tempDir), "#B3");
\r
774 public void MoveFile_DestFile_Exists ()
\r
776 string tempFile1 = Path.Combine (TempFolder, "temp1.txt");
\r
777 string tempFile2 = Path.Combine (TempFolder, "temp2.txt");
\r
779 using (StreamWriter sw = File.CreateText (tempFile1)) {
\r
780 sw.Write ("temp1");
\r
782 using (StreamWriter sw = File.CreateText (tempFile2)) {
\r
783 sw.Write ("temp2");
\r
787 Directory.Move (tempFile1, tempFile2);
\r
788 Assert.Fail ("#A1");
\r
789 } catch (IOException ex) {
\r
790 // Cannot create a file when that file already exists
\r
791 Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");
\r
792 Assert.IsNull (ex.InnerException, "#A3");
\r
793 Assert.IsNotNull (ex.Message, "#A4");
\r
796 Assert.IsTrue (File.Exists (tempFile1), "#B1");
\r
797 using (StreamReader sr = File.OpenText (tempFile1)) {
\r
798 Assert.AreEqual ("temp1", sr.ReadToEnd (), "#B2");
\r
801 Assert.IsTrue (File.Exists (tempFile2), "#C1");
\r
802 using (StreamReader sr = File.OpenText (tempFile2)) {
\r
803 Assert.AreEqual ("temp2", sr.ReadToEnd (), "#C2");
\r
808 public void MoveFile_Same ()
\r
810 string tempFile = Path.Combine (TempFolder, "temp.txt");
\r
813 Directory.Move (tempFile, tempFile);
\r
814 Assert.Fail ("#1");
\r
815 } catch (IOException ex) {
\r
816 // Source and destination path must be different
\r
817 Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
\r
818 Assert.IsNull (ex.InnerException, "#3");
\r
819 Assert.IsNotNull (ex.Message, "#4");
\r
824 [ExpectedException(typeof(ArgumentException))]
\r
825 [Ignore ("On IA64, causes nunit to abort due to bug #76388")]
\r
826 public void MoveException4 ()
\r
828 string path = TempFolder + DSC + "DirectoryTest.Test.13";
\r
829 path += Path.InvalidPathChars [0];
\r
830 string path2 = TempFolder + DSC + "DirectoryTest.Test.13";
\r
831 DeleteDirectory (path);
\r
832 DeleteDirectory (path2);
\r
834 Directory.CreateDirectory (path2);
\r
835 Directory.Move (path2, path);
\r
837 DeleteDirectory (path);
\r
838 DeleteDirectory (path2);
\r
843 [ExpectedException(typeof(DirectoryNotFoundException))]
\r
844 public void MoveException5 ()
\r
846 string path = TempFolder + DSC + "DirectoryTest.Test.14";
\r
847 DeleteDirectory (path);
\r
849 Directory.Move (path, path + "Test.Test");
\r
851 DeleteDirectory (path);
\r
852 DeleteDirectory (path + "Test.Test");
\r
857 [ExpectedException(typeof(IOException))]
\r
858 public void MoveDirectory_Dest_SubDir ()
\r
860 string path = TempFolder + DSC + "DirectoryTest.Test.15";
\r
861 DeleteDirectory (path);
\r
863 Directory.CreateDirectory (path);
\r
864 Directory.Move (path, path + DSC + "dir");
\r
866 DeleteDirectory (path);
\r
867 DeleteDirectory (path + DSC + "dir");
\r
872 [ExpectedException (typeof (IOException))]
\r
873 public void MoveDirectory_Dest_Exists ()
\r
875 string path = TempFolder + DSC + "DirectoryTest.Test.16";
\r
876 string path2 = TempFolder + DSC + "DirectoryTest.Test.17";
\r
878 DeleteDirectory (path);
\r
879 DeleteDirectory (path2);
\r
881 Directory.CreateDirectory (path);
\r
882 Directory.CreateDirectory (path2);
\r
883 Directory.Move (path, path2);
\r
885 DeleteDirectory (path);
\r
886 DeleteDirectory (path2);
\r
891 [Category("TargetJvmNotSupported")] // CreationTime not supported for TARGET_JVM
\r
892 public void CreationTime ()
\r
895 Assert.Ignore ("Unix doesn't support CreationTime");
\r
897 string path = TempFolder + DSC + "DirectoryTest.CreationTime.1";
\r
898 DeleteDirectory (path);
\r
901 Directory.CreateDirectory (path);
\r
902 Directory.SetCreationTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
904 DateTime time = Directory.GetCreationTime (path);
\r
905 Assert.AreEqual (2003, time.Year, "#A1");
\r
906 Assert.AreEqual (6, time.Month, "#A2");
\r
907 Assert.AreEqual (4, time.Day, "#A3");
\r
908 Assert.AreEqual (6, time.Hour, "#A4");
\r
909 Assert.AreEqual (4, time.Minute, "#A5");
\r
910 Assert.AreEqual (0, time.Second, "#A6");
\r
912 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetCreationTimeUtc (path));
\r
913 Assert.AreEqual (2003, time.Year, "#B1");
\r
914 Assert.AreEqual (6, time.Month, "#B2");
\r
915 Assert.AreEqual (4, time.Day, "#B3");
\r
916 Assert.AreEqual (6, time.Hour, "#B4");
\r
917 Assert.AreEqual (4, time.Minute, "#B5");
\r
918 Assert.AreEqual (0, time.Second, "#B6");
\r
920 Directory.SetCreationTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
921 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetCreationTime (path));
\r
922 Assert.AreEqual (2003, time.Year, "#C1");
\r
923 Assert.AreEqual (6, time.Month, "#C2");
\r
924 Assert.AreEqual (4, time.Day, "#C3");
\r
925 Assert.AreEqual (6, time.Hour, "#C4");
\r
926 Assert.AreEqual (4, time.Minute, "#C5");
\r
927 Assert.AreEqual (0, time.Second, "#C6");
\r
929 time = Directory.GetCreationTimeUtc (path);
\r
930 Assert.AreEqual (2003, time.Year, "#D1");
\r
931 Assert.AreEqual (6, time.Month, "#D2");
\r
932 Assert.AreEqual (4, time.Day, "#D3");
\r
933 Assert.AreEqual (6, time.Hour, "#D4");
\r
934 Assert.AreEqual (4, time.Minute, "#D5");
\r
935 Assert.AreEqual (0, time.Second, "#D6");
\r
937 DeleteDirectory (path);
\r
942 [Category("TargetJvmNotSupported")] // LastAccessTime not supported for TARGET_JVM
\r
943 public void LastAccessTime ()
\r
945 string path = TempFolder + DSC + "DirectoryTest.AccessTime.1";
\r
946 DeleteDirectory (path);
\r
949 Directory.CreateDirectory (path);
\r
950 Directory.SetLastAccessTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
952 DateTime time = Directory.GetLastAccessTime (path);
\r
953 Assert.AreEqual (2003, time.Year, "#A1");
\r
954 Assert.AreEqual (6, time.Month, "#A2");
\r
955 Assert.AreEqual (4, time.Day, "#A3");
\r
956 Assert.AreEqual (6, time.Hour, "#A4");
\r
957 Assert.AreEqual (4, time.Minute, "#A5");
\r
958 Assert.AreEqual (0, time.Second, "#A6");
\r
960 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastAccessTimeUtc (path));
\r
961 Assert.AreEqual (2003, time.Year, "#B1");
\r
962 Assert.AreEqual (6, time.Month, "#B2");
\r
963 Assert.AreEqual (4, time.Day, "#B3");
\r
964 Assert.AreEqual (6, time.Hour, "#B4");
\r
965 Assert.AreEqual (4, time.Minute, "#B5");
\r
966 Assert.AreEqual (0, time.Second, "#B6");
\r
968 Directory.SetLastAccessTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
969 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastAccessTime (path));
\r
970 Assert.AreEqual (2003, time.Year, "#C1");
\r
971 Assert.AreEqual (6, time.Month, "#C2");
\r
972 Assert.AreEqual (4, time.Day, "#C3");
\r
973 Assert.AreEqual (6, time.Hour, "#C4");
\r
974 Assert.AreEqual (4, time.Minute, "#C5");
\r
975 Assert.AreEqual (0, time.Second, "#C6");
\r
977 time = Directory.GetLastAccessTimeUtc (path);
\r
978 Assert.AreEqual (2003, time.Year, "#D1");
\r
979 Assert.AreEqual (6, time.Month, "#D2");
\r
980 Assert.AreEqual (4, time.Day, "#D3");
\r
981 Assert.AreEqual (6, time.Hour, "#D4");
\r
982 Assert.AreEqual (4, time.Minute, "#D5");
\r
983 Assert.AreEqual (0, time.Second, "#D6");
\r
985 DeleteDirectory (path);
\r
990 public void LastWriteTime ()
\r
992 string path = TempFolder + DSC + "DirectoryTest.WriteTime.1";
\r
993 DeleteDirectory (path);
\r
996 Directory.CreateDirectory (path);
\r
997 Directory.SetLastWriteTime (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
999 DateTime time = Directory.GetLastWriteTime (path);
\r
1000 Assert.AreEqual (2003, time.Year, "#A1");
\r
1001 Assert.AreEqual (6, time.Month, "#A2");
\r
1002 Assert.AreEqual (4, time.Day, "#A3");
\r
1003 Assert.AreEqual (6, time.Hour, "#A4");
\r
1004 Assert.AreEqual (4, time.Minute, "#A5");
\r
1005 Assert.AreEqual (0, time.Second, "#A6");
\r
1007 time = TimeZone.CurrentTimeZone.ToLocalTime (Directory.GetLastWriteTimeUtc (path));
\r
1008 Assert.AreEqual (2003, time.Year, "#B1");
\r
1009 Assert.AreEqual (6, time.Month, "#B2");
\r
1010 Assert.AreEqual (4, time.Day, "#B3");
\r
1011 Assert.AreEqual (6, time.Hour, "#B4");
\r
1012 Assert.AreEqual (4, time.Minute, "#B5");
\r
1013 Assert.AreEqual (0, time.Second, "#B6");
\r
1015 Directory.SetLastWriteTimeUtc (path, new DateTime (2003, 6, 4, 6, 4, 0));
\r
1016 time = TimeZone.CurrentTimeZone.ToUniversalTime (Directory.GetLastWriteTime (path));
\r
1017 Assert.AreEqual (2003, time.Year, "#C1");
\r
1018 Assert.AreEqual (6, time.Month, "#C2");
\r
1019 Assert.AreEqual (4, time.Day, "#C3");
\r
1020 Assert.AreEqual (6, time.Hour, "#C4");
\r
1021 Assert.AreEqual (4, time.Minute, "#C5");
\r
1022 Assert.AreEqual (0, time.Second, "#C6");
\r
1024 time = Directory.GetLastWriteTimeUtc (path);
\r
1025 Assert.AreEqual (2003, time.Year, "#D1");
\r
1026 Assert.AreEqual (6, time.Month, "#D2");
\r
1027 Assert.AreEqual (4, time.Day, "#D3");
\r
1028 Assert.AreEqual (6, time.Hour, "#D4");
\r
1029 Assert.AreEqual (4, time.Minute, "#D5");
\r
1030 Assert.AreEqual (0, time.Second, "#D6");
\r
1032 DeleteDirectory (path);
\r
1037 [ExpectedException(typeof(ArgumentNullException))]
\r
1038 public void SetLastWriteTimeException1 ()
\r
1040 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1041 Directory.SetLastWriteTime (null as string, time);
\r
1045 [ExpectedException(typeof(ArgumentException))]
\r
1046 public void SetLastWriteTimeException2 ()
\r
1048 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1049 Directory.SetLastWriteTime ("", time);
\r
1053 [ExpectedException(typeof(FileNotFoundException))]
\r
1054 public void SetLastWriteTimeException3 ()
\r
1056 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1057 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTime.2";
\r
1058 DeleteDirectory (path);
\r
1060 Directory.SetLastWriteTime (path, time);
\r
1062 DeleteDirectory (path);
\r
1067 [ExpectedException(typeof(ArgumentException))]
\r
1068 public void SetLastWriteTimeException4 ()
\r
1070 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1071 Directory.SetLastWriteTime (" ", time);
\r
1075 [ExpectedException(typeof(ArgumentException))]
\r
1076 public void SetLastWriteTimeException5 ()
\r
1078 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1079 Directory.SetLastWriteTime (Path.InvalidPathChars [0].ToString (), time);
\r
1083 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1084 // public void SetLastWriteTimeException6 ()
\r
1086 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1087 // string path = TempFolder + Path.DirectorySeparatorChar + "DirectoryTest.SetLastWriteTime.1";
\r
1090 // if (!Directory.Exists (path))
\r
1091 // Directory.CreateDirectory (path);
\r
1093 // Directory.SetLastWriteTime (path, time);
\r
1095 // DeleteDirectory (path);
\r
1101 [ExpectedException(typeof(ArgumentNullException))]
\r
1102 public void SetLastWriteTimeUtcException1 ()
\r
1104 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1105 Directory.SetLastWriteTimeUtc (null as string, time);
\r
1109 [ExpectedException(typeof(ArgumentException))]
\r
1110 public void SetLastWriteTimeUtcException2 ()
\r
1112 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1113 Directory.SetLastWriteTimeUtc ("", time);
\r
1117 [ExpectedException(typeof(FileNotFoundException))]
\r
1118 public void SetLastWriteTimeUtcException3 ()
\r
1120 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1121 string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.2";
\r
1122 DeleteDirectory (path);
\r
1124 Directory.SetLastWriteTimeUtc (path, time);
\r
1126 DeleteDirectory (path);
\r
1131 [ExpectedException(typeof(ArgumentException))]
\r
1132 public void SetLastWriteTimeUtcException4 ()
\r
1134 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1135 Directory.SetLastWriteTimeUtc (" ", time);
\r
1139 [ExpectedException(typeof(ArgumentException))]
\r
1140 public void SetLastWriteTimeUtcException5 ()
\r
1142 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1143 Directory.SetLastWriteTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1147 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1148 // public void SetLastWriteTimeUtcException6 ()
\r
1150 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1151 // string path = TempFolder + DSC + "DirectoryTest.SetLastWriteTimeUtc.1";
\r
1153 // if (!Directory.Exists (path))
\r
1154 // Directory.CreateDirectory (path);
\r
1156 // Directory.SetLastWriteTimeUtc (path, time);
\r
1158 // DeleteDirectory (path);
\r
1163 [ExpectedException(typeof(ArgumentNullException))]
\r
1164 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1165 public void SetLastAccessTimeException1 ()
\r
1167 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1168 Directory.SetLastAccessTime (null as string, time);
\r
1172 [ExpectedException(typeof(ArgumentException))]
\r
1173 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1174 public void SetLastAccessTimeException2 ()
\r
1176 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1177 Directory.SetLastAccessTime ("", time);
\r
1181 [ExpectedException(typeof(FileNotFoundException))]
\r
1182 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1183 public void SetLastAccessTimeException3 ()
\r
1185 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1186 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.2";
\r
1187 DeleteDirectory (path);
\r
1189 Directory.SetLastAccessTime (path, time);
\r
1191 DeleteDirectory (path);
\r
1196 [ExpectedException(typeof(ArgumentException))]
\r
1197 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1198 public void SetLastAccessTimeException4 ()
\r
1200 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1201 Directory.SetLastAccessTime (" ", time);
\r
1205 [ExpectedException(typeof(ArgumentException))]
\r
1206 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1207 public void SetLastAccessTimeException5 ()
\r
1209 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1210 Directory.SetLastAccessTime (Path.InvalidPathChars [0].ToString (), time);
\r
1214 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1215 // public void SetLastAccessTimeException6 ()
\r
1217 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1218 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTime.1";
\r
1220 // if (!Directory.Exists (path))
\r
1221 // Directory.CreateDirectory (path);
\r
1223 // Directory.SetLastAccessTime (path, time);
\r
1225 // DeleteDirectory (path);
\r
1231 [ExpectedException(typeof(ArgumentNullException))]
\r
1232 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1233 public void SetLastAccessTimeUtcException1 ()
\r
1235 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1236 Directory.SetLastAccessTimeUtc (null as string, time);
\r
1240 [ExpectedException(typeof(ArgumentException))]
\r
1241 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1242 public void SetLastAccessTimeUtcException2 ()
\r
1244 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1245 Directory.SetLastAccessTimeUtc ("", time);
\r
1249 [ExpectedException(typeof(FileNotFoundException))]
\r
1250 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1251 public void SetLastAccessTimeUtcException3 ()
\r
1253 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1254 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1255 DeleteDirectory (path);
\r
1257 Directory.SetLastAccessTimeUtc (path, time);
\r
1259 DeleteDirectory (path);
\r
1264 [ExpectedException(typeof(ArgumentException))]
\r
1265 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1266 public void SetLastAccessTimeUtcException4 ()
\r
1268 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1269 Directory.SetLastAccessTimeUtc (" ", time);
\r
1273 [ExpectedException(typeof(ArgumentException))]
\r
1274 [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
\r
1275 public void SetLastAccessTimeUtcException5 ()
\r
1277 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1278 Directory.SetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1282 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1283 // public void SetLastAccessTimeUtcException6 ()
\r
1285 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1286 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1288 // if (!Directory.Exists (path))
\r
1289 // Directory.CreateDirectory (path);
\r
1291 // Directory.SetLastAccessTimeUtc (path, time);
\r
1293 // DeleteDirectory (path);
\r
1298 [ExpectedException(typeof(ArgumentNullException))]
\r
1299 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1300 public void SetCreationTimeException1 ()
\r
1302 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1303 Directory.SetCreationTime (null as string, time);
\r
1307 [ExpectedException(typeof(ArgumentException))]
\r
1308 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1309 public void SetCreationTimeException2 ()
\r
1311 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1312 Directory.SetCreationTime ("", time);
\r
1316 [ExpectedException(typeof(FileNotFoundException))]
\r
1317 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1318 public void SetCreationTimeException3 ()
\r
1320 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1321 string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.2";
\r
1322 DeleteDirectory (path);
\r
1325 Directory.SetCreationTime (path, time);
\r
1327 DeleteDirectory (path);
\r
1332 [ExpectedException(typeof(ArgumentException))]
\r
1333 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1334 public void SetCreationTimeException4 ()
\r
1336 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1337 Directory.SetCreationTime (" ", time);
\r
1341 [ExpectedException(typeof(ArgumentException))]
\r
1342 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1343 public void SetCreationTimeException5 ()
\r
1345 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1346 Directory.SetCreationTime (Path.InvalidPathChars [0].ToString (), time);
\r
1350 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1351 // public void SetCreationTimeException6 ()
\r
1353 // DateTime time = new DateTime (1003, 4, 6, 6, 4, 2);
\r
1354 // string path = TempFolder + DSC + "DirectoryTest.SetCreationTime.1";
\r
1356 // if (!Directory.Exists (path))
\r
1357 // Directory.CreateDirectory (path);
\r
1359 // Directory.SetCreationTime (path, time);
\r
1360 // DeleteDirectory (path);
\r
1362 // DeleteDirectory (path);
\r
1368 [ExpectedException(typeof(ArgumentNullException))]
\r
1369 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1370 public void SetCreationTimeUtcException1 ()
\r
1372 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1373 Directory.SetCreationTimeUtc (null as string, time);
\r
1377 [ExpectedException(typeof(ArgumentException))]
\r
1378 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1379 public void SetCreationTimeUtcException2 ()
\r
1381 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1382 Directory.SetCreationTimeUtc ("", time);
\r
1386 [ExpectedException(typeof(FileNotFoundException))]
\r
1387 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1388 public void SetCreationTimeUtcException3 ()
\r
1390 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1391 string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.2";
\r
1392 DeleteDirectory (path);
\r
1395 Directory.SetCreationTimeUtc (path, time);
\r
1396 DeleteDirectory (path);
\r
1398 DeleteDirectory (path);
\r
1403 [ExpectedException(typeof(ArgumentException))]
\r
1404 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1405 public void SetCreationTimeUtcException4 ()
\r
1407 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1408 Directory.SetCreationTimeUtc (" ", time);
\r
1412 [ExpectedException(typeof(ArgumentException))]
\r
1413 [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
\r
1414 public void SetCreationTimeUtcException5 ()
\r
1416 DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);
\r
1417 Directory.SetCreationTimeUtc (Path.InvalidPathChars [0].ToString (), time);
\r
1421 // [ExpectedException(typeof(ArgumentOutOfRangeException))]
\r
1422 // public void SetCreationTimeUtcException6 ()
\r
1424 // DateTime time = new DateTime (1000, 4, 6, 6, 4, 2);
\r
1425 // string path = TempFolder + DSC + "DirectoryTest.SetLastAccessTimeUtc.1";
\r
1427 // if (!Directory.Exists (path))
\r
1428 // Directory.CreateDirectory (path);
\r
1430 // Directory.SetCreationTimeUtc (path, time);
\r
1431 // DeleteDirectory (path);
\r
1433 // DeleteDirectory (path);
\r
1438 public void GetDirectories ()
\r
1440 string path = TempFolder;
\r
1441 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetDirectories";
\r
1442 DeleteDirectory (DirPath);
\r
1445 Directory.CreateDirectory (DirPath);
\r
1447 string [] dirs = Directory.GetDirectories (path);
\r
1449 foreach (string directory in dirs) {
\r
1451 if (directory == DirPath)
\r
1455 Assert.Fail ("Directory Not Found");
\r
1457 DeleteDirectory (DirPath);
\r
1461 [Test] // bug #346123
\r
1462 [Category ("NotWorking")]
\r
1463 public void GetDirectories_Backslash ()
\r
1465 if (!RunningOnUnix)
\r
1466 // on Windows, backslash is used as directory separator
\r
1469 string dir = Path.Combine (TempFolder, @"sub\dir");
\r
1470 Directory.CreateDirectory (dir);
\r
1472 Assert.IsTrue (Directory.Exists (dir), "#A1");
\r
1473 Assert.IsFalse (Directory.Exists (Path.Combine (TempFolder, "dir")), "#A2");
\r
1475 string [] dirs = Directory.GetDirectories (TempFolder);
\r
1476 Assert.AreEqual (1, dirs.Length, "#B1");
\r
1477 Assert.AreEqual (dir, dirs [0], "#B2");
\r
1481 public void GetParentOfRootDirectory ()
\r
1483 DirectoryInfo info;
\r
1485 info = Directory.GetParent (Path.GetPathRoot (Path.GetTempPath ()));
\r
1486 Assert.IsNull (info);
\r
1490 public void GetFiles ()
\r
1492 string path = TempFolder;
\r
1493 string DirPath = TempFolder + Path.DirectorySeparatorChar + ".GetFiles";
\r
1494 if (File.Exists (DirPath))
\r
1495 File.Delete (DirPath);
\r
1498 File.Create (DirPath).Close ();
\r
1499 string [] files = Directory.GetFiles (TempFolder);
\r
1500 foreach (string directory in files) {
\r
1502 if (directory == DirPath)
\r
1506 Assert.Fail ("File Not Found");
\r
1508 if (File.Exists (DirPath))
\r
1509 File.Delete (DirPath);
\r
1513 [Test] // bug #346123
\r
1514 [Category ("NotWorking")]
\r
1515 public void GetFiles_Backslash ()
\r
1517 if (!RunningOnUnix)
\r
1518 // on Windows, backslash is used as directory separator
\r
1521 string file = Path.Combine (TempFolder, @"doc\temp1.file");
\r
1522 File.Create (file).Close ();
\r
1524 Assert.IsTrue (File.Exists (file), "#A1");
\r
1525 Assert.IsFalse (File.Exists (Path.Combine (TempFolder, "temp1.file")), "#A2");
\r
1527 string [] files = Directory.GetFiles (TempFolder);
\r
1528 Assert.AreEqual (1, files.Length, "#B1");
\r
1529 Assert.AreEqual (file, files [0], "#B2");
\r
1532 [Test] // bug #82212 and bug #325107
\r
1533 public void GetFiles_Pattern ()
\r
1535 string [] files = Directory.GetFiles (TempFolder, "*.*");
\r
1536 Assert.IsNotNull (files, "#A1");
\r
1537 Assert.AreEqual (0, files.Length, "#A2");
\r
1539 string tempFile1 = Path.Combine (TempFolder, "tempFile1");
\r
1540 File.Create (tempFile1).Close ();
\r
1542 files = Directory.GetFiles (TempFolder, "*.*");
\r
1543 Assert.IsNotNull (files, "#B1");
\r
1544 Assert.AreEqual (1, files.Length, "#B2");
\r
1545 Assert.AreEqual (tempFile1, files [0], "#B3");
\r
1547 string tempFile2 = Path.Combine (TempFolder, "FileTemp2.tmp");
\r
1548 File.Create (tempFile2).Close ();
\r
1550 files = Directory.GetFiles (TempFolder, "*.*");
\r
1551 Assert.IsNotNull (files, "#C1");
\r
1552 Assert.AreEqual (2, files.Length, "#C2");
\r
1554 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1555 Assert.IsNotNull (files, "#D1");
\r
1556 Assert.AreEqual (1, files.Length, "#D2");
\r
1557 Assert.AreEqual (tempFile1, files [0], "#D3");
\r
1559 string tempFile3 = Path.Combine (TempFolder, "tempFile3.txt");
\r
1560 File.Create (tempFile3).Close ();
\r
1562 files = Directory.GetFiles (TempFolder, "*File*.*");
\r
1563 Assert.IsNotNull (files, "#E1");
\r
1564 Assert.AreEqual (3, files.Length, "#E2");
\r
1566 files = Directory.GetFiles (TempFolder, "*File*.tmp");
\r
1567 Assert.IsNotNull (files, "#F1");
\r
1568 Assert.AreEqual (1, files.Length, "#F2");
\r
1569 Assert.AreEqual (tempFile2, files [0], "#F3");
\r
1571 files = Directory.GetFiles (TempFolder, "*tempFile*");
\r
1572 Assert.IsNotNull (files, "#G1");
\r
1573 Assert.AreEqual (2, files.Length, "#G2");
\r
1575 files = Directory.GetFiles (TempFolder, "*tempFile1");
\r
1576 Assert.IsNotNull (files, "#H1");
\r
1577 Assert.AreEqual (1, files.Length, "#H2");
\r
1578 Assert.AreEqual (tempFile1, files [0], "#H3");
\r
1580 files = Directory.GetFiles (TempFolder, "*.txt");
\r
1581 Assert.IsNotNull (files, "#I1");
\r
1582 Assert.AreEqual (1, files.Length, "#I2");
\r
1583 Assert.AreEqual (tempFile3, files [0], "#I3");
\r
1585 files = Directory.GetFiles (TempFolder, "*.t*");
\r
1586 Assert.IsNotNull (files, "#J1");
\r
1587 Assert.AreEqual (2, files.Length, "#J2");
\r
1589 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1590 Assert.IsNotNull (files, "#K1");
\r
1591 Assert.AreEqual (2, files.Length, "#K2");
\r
1593 File.Delete (tempFile1);
\r
1595 files = Directory.GetFiles (TempFolder, "temp*.*");
\r
1596 Assert.IsNotNull (files, "#L1");
\r
1597 Assert.AreEqual (1, files.Length, "#L2");
\r
1598 Assert.AreEqual (tempFile3, files [0], "#L3");
\r
1600 files = Directory.GetFiles (TempFolder, ".*");
\r
1601 Assert.IsNotNull (files, "#M1");
\r
1602 Assert.AreEqual (0, files.Length, "#M2");
\r
1604 string tempFile4 = Path.Combine (TempFolder, "tempFile4.");
\r
1605 File.Create (tempFile4).Close ();
\r
1607 files = Directory.GetFiles (TempFolder, "temp*.");
\r
1608 Assert.IsNotNull (files, "#N1");
\r
1609 Assert.AreEqual (1, files.Length, "#N2");
\r
1610 if (RunningOnUnix)
\r
1611 Assert.AreEqual (tempFile4, files [0], "#N3");
\r
1612 else // on Windows, the trailing dot is automatically trimmed
\r
1613 Assert.AreEqual (Path.Combine (TempFolder, "tempFile4"), files [0], "#N3");
\r
1617 [ExpectedException (typeof (ArgumentNullException))]
\r
1618 public void SetCurrentDirectoryNull ()
\r
1620 Directory.SetCurrentDirectory (null);
\r
1624 [ExpectedException (typeof (ArgumentException))]
\r
1625 public void SetCurrentDirectoryEmpty ()
\r
1627 Directory.SetCurrentDirectory (String.Empty);
\r
1631 [ExpectedException (typeof (ArgumentException))]
\r
1632 public void SetCurrentDirectoryWhitespace ()
\r
1634 Directory.SetCurrentDirectory (" ");
\r
1639 public void GetNoFiles () // Bug 58875. This throwed an exception on windows.
\r
1641 DirectoryInfo dir = new DirectoryInfo (".");
\r
1642 dir.GetFiles ("*.nonext");
\r
1646 public void FilenameOnly () // bug 78209
\r
1648 Directory.GetParent ("somefile");
\r
1651 private static bool RunningOnUnix {
\r
1653 // check for Unix platforms - see FAQ for more details
\r
1654 // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F
\r
1655 int platform = (int) Environment.OSVersion.Platform;
\r
1656 return ((platform == 4) || (platform == 128));
\r
1660 private void DeleteDirectory (string path)
\r
1662 if (Directory.Exists (path))
\r
1663 Directory.Delete (path, true);
\r
1666 private void DeleteFile (string path)
\r
1668 if (File.Exists (path))
\r
1669 File.Delete (path);
\r