Merge pull request #270 from bholmes/COM_cctor
[mono.git] / mcs / class / corlib / Test / System.IO / DirectoryTest.cs
index a8f5692dd2f6b959d2e5a00b4e457979d9355ea1..9891683b995cafc66c2b7bc4a4172b9c7c0a05b2 100644 (file)
@@ -9,20 +9,23 @@
 // TODO: Find out why ArgumentOutOfRange tests does not release directories properly\r
 //\r
 \r
-using NUnit.Framework;\r
-using System.IO;\r
-using System.Text;\r
 using System;\r
+using System.Diagnostics;\r
 using System.Globalization;\r
+using System.IO;\r
+using System.Text;\r
 using System.Threading;\r
-using System.Diagnostics;\r
 \r
-namespace MonoTests.System.IO {\r
+using NUnit.Framework;\r
+\r
+namespace MonoTests.System.IO\r
+{\r
 \r
 [TestFixture]\r
 public class DirectoryTest\r
 {\r
-       string TempFolder = Path.Combine (Path.GetTempPath (), "MonoTests.System.IO.Tests");\r
+       static readonly string TempSubFolder = "MonoTests.System.IO.Tests";\r
+       string TempFolder = Path.Combine (Path.GetTempPath (), TempSubFolder);\r
        static readonly char DSC = Path.DirectorySeparatorChar;\r
 \r
        [SetUp]\r
@@ -35,7 +38,8 @@ public class DirectoryTest
        }\r
        \r
        [TearDown]\r
-       public void TearDown () {\r
+       public void TearDown ()\r
+       {\r
                if (Directory.Exists (TempFolder))\r
                        Directory.Delete (TempFolder, true);\r
        }\r
@@ -56,49 +60,85 @@ public class DirectoryTest
                }\r
        }\r
        \r
+       /* Commented out: a directory named ":" is legal in unix\r
        [Test]\r
        public void CreateDirectoryNotSupportedException ()\r
        {\r
                DeleteDirectory (":");\r
                try {\r
                        DirectoryInfo info = Directory.CreateDirectory (":");\r
-                       Assert.Fail ();\r
-               } catch (ArgumentException) {\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentException ex) {\r
+                       // The path is not of a legal form\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNull (ex.ParamName, "#5");\r
                }\r
                DeleteDirectory (":");\r
        }\r
+       */\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentNullException))]\r
-       public void CreateDirectoryArgumentNullException ()\r
+       public void CreateDirectory_Path_Null ()\r
        {\r
-               DirectoryInfo info = Directory.CreateDirectory (null as string);\r
+               try {\r
+                       Directory.CreateDirectory (null as string);\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentNullException ex) {\r
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.AreEqual ("path", ex.ParamName, "#5");\r
+               }\r
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentException))]\r
-       public void CreateDirectoryArgumentException1 ()\r
+       public void CreateDirectory_Path_Empty ()\r
        {\r
-               DirectoryInfo info = Directory.CreateDirectory ("");\r
+               try {\r
+                       Directory.CreateDirectory (string.Empty);\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentException ex) {\r
+                       // Path cannot be the empty string or all whitespace\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNull (ex.ParamName, "#5");\r
+               }\r
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentException))]\r
-       public void CreateDirectoryArgumentException2 ()\r
+       public void CreateDirectory_Path_Whitespace ()\r
        {\r
-               DirectoryInfo info = Directory.CreateDirectory ("            ");\r
+               try {\r
+                       Directory.CreateDirectory ("            ");\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentException ex) {\r
+                       // The path is not of a legal form\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNull (ex.ParamName, "#5");\r
+               }\r
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentException))]\r
-       public void CreateDirectoryArgumentException3 ()\r
+       public void CreateDirectory_Path_InvalidChars ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.Test";\r
                DeleteDirectory (path);\r
                try {\r
-                       path += Path.InvalidPathChars [0];\r
+                       path += '\x00';\r
                        path += ".2";\r
                        DirectoryInfo info = Directory.CreateDirectory (path);\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentException ex) {\r
+                       // The path contains illegal characters\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNull (ex.ParamName, "#5");\r
                } finally {\r
                        DeleteDirectory (path);\r
                }\r
@@ -135,6 +175,10 @@ public class DirectoryTest
 #if NET_2_0\r
                        Assert.Fail ("#1");\r
                } catch (IOException ex) {\r
+                       Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");\r
+                       // exception message contains the path\r
+                       Assert.IsTrue (ex.Message.Contains (path), "#3");\r
+                       Assert.IsNull (ex.InnerException, "#4");\r
 #else\r
                        Assert.IsFalse (dinfo.Exists, "#2");\r
                        Assert.IsTrue (dinfo.FullName.EndsWith ("DirectoryTest.Test.ExistsAsFile"), "#3");\r
@@ -183,7 +227,7 @@ public class DirectoryTest
        [ExpectedException(typeof(ArgumentException))]\r
        public void DeleteArgumentException ()\r
        {\r
-               Directory.Delete ("");\r
+               Directory.Delete (string.Empty);\r
        }\r
 \r
        [Test]  \r
@@ -239,34 +283,59 @@ public class DirectoryTest
                };\r
        }\r
 \r
+       [Test]\r
+       public void DeleteDirectoryOnExistingFileName ()\r
+       {\r
+               string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile";\r
+               DeleteDirectory (path);\r
+               DeleteFile (path);\r
+               try {\r
+                       FileStream fstream = File.Create (path);\r
+                       fstream.Close ();\r
+\r
+                       Directory.Delete (path);\r
+                       Assert.Fail ("#1");\r
+               }\r
+               catch (IOException ex) {\r
+                       Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");\r
+                       // exception message DOES NOT contains the path\r
+                       Assert.IsFalse (ex.Message.IndexOf (path) >= 0, "#3");\r
+                       Assert.IsNull (ex.InnerException, "#4");\r
+               }\r
+               finally {\r
+                       DeleteDirectory (path);\r
+                       DeleteFile (path);\r
+               }\r
+       }\r
+\r
        [Test]\r
        public void Exists ()\r
        {\r
                Assert.IsFalse (Directory.Exists (null as string));\r
        }\r
 \r
-       [Test]\r
-       [Category("NotDotNet")]\r
+#if !TARGET_JVM // We don't support yet the Process class.\r
+       [Test] // bug #78239\r
        public void ExistsAccessDenied ()\r
        {\r
-               // bug #78239\r
-\r
-               if (Path.DirectorySeparatorChar == '\\')\r
+               if (!RunningOnUnix)\r
                        return; // this test does not work on Windows.\r
 \r
                string path = TempFolder + DSC + "ExistsAccessDenied";\r
 \r
                Directory.CreateDirectory (path);\r
-               Process.Start ("/bin/chmod", "000 " + path).WaitForExit ();\r
+               Mono.Posix.Syscall.chmod (path, 0);\r
                try {\r
                        Assert.IsFalse (Directory.Exists(path + DSC + "b"));\r
                } finally {\r
-                       Process.Start ("/bin/chmod", "755 " + path).WaitForExit ();\r
+                       Mono.Posix.Syscall.chmod (path, (Mono.Posix.FileMode) 755);\r
                        Directory.Delete (path);\r
                }\r
        }\r
+#endif\r
        \r
        [Test]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        [ExpectedException(typeof(ArgumentNullException))]\r
        public void GetCreationTimeException1 ()\r
        {\r
@@ -275,15 +344,17 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeException2 ()\r
        {\r
-               Directory.GetCreationTime ("");\r
+               Directory.GetCreationTime (string.Empty);\r
        }\r
        \r
        [Test]\r
 #if !NET_2_0\r
        [ExpectedException(typeof(IOException))]\r
 #endif\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeException_NonExistingPath ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.GetCreationTime.1";\r
@@ -307,6 +378,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeException4 ()\r
        {\r
                Directory.GetCreationTime ("    ");\r
@@ -314,6 +386,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeException5 ()\r
        {\r
                Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());\r
@@ -321,6 +394,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeUtcException1 ()\r
        {\r
                Directory.GetCreationTimeUtc (null as string);\r
@@ -328,15 +402,17 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeUtcException2 ()\r
        {\r
-               Directory.GetCreationTimeUtc ("");\r
+               Directory.GetCreationTimeUtc (string.Empty);\r
        }\r
        \r
        [Test]\r
 #if !NET_2_0\r
        [ExpectedException (typeof (IOException))]\r
 #endif\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeUtc_NonExistingPath ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.GetCreationTimeUtc.1";\r
@@ -360,6 +436,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeUtcException4 ()\r
        {\r
                Directory.GetCreationTimeUtc ("    ");\r
@@ -367,6 +444,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM\r
        public void GetCreationTimeUtcException5 ()\r
        {\r
                Directory.GetCreationTime (Path.InvalidPathChars [0].ToString ());\r
@@ -374,6 +452,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTime_Null ()\r
        {\r
                Directory.GetLastAccessTime (null as string);\r
@@ -381,15 +460,17 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeException2 ()\r
        {\r
-               Directory.GetLastAccessTime ("");\r
+               Directory.GetLastAccessTime (string.Empty);\r
        }\r
        \r
        [Test]\r
 #if !NET_2_0\r
        [ExpectedException (typeof (IOException))]\r
 #endif\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTime_NonExistingPath ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTime.1";\r
@@ -414,6 +495,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeException4 ()\r
        {\r
                Directory.GetLastAccessTime ("    ");\r
@@ -421,6 +503,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeException5 ()\r
        {\r
                Directory.GetLastAccessTime (Path.InvalidPathChars [0].ToString ());\r
@@ -428,6 +511,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeUtc_Null ()\r
        {\r
                Directory.GetLastAccessTimeUtc (null as string);\r
@@ -435,15 +519,17 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeUtcException2 ()\r
        {\r
-               Directory.GetLastAccessTimeUtc ("");\r
+               Directory.GetLastAccessTimeUtc (string.Empty);\r
        }\r
        \r
        [Test]\r
 #if !NET_2_0\r
        [ExpectedException (typeof (IOException))]\r
 #endif\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeUtc_NonExistingPath ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.GetLastAccessTimeUtc.1";\r
@@ -466,6 +552,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeUtcException4 ()\r
        {\r
                Directory.GetLastAccessTimeUtc ("    ");\r
@@ -473,6 +560,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM\r
        public void GetLastAccessTimeUtcException5 ()\r
        {\r
                Directory.GetLastAccessTimeUtc (Path.InvalidPathChars [0].ToString ());\r
@@ -489,7 +577,7 @@ public class DirectoryTest
        [ExpectedException(typeof(ArgumentException))]\r
        public void GetLastWriteTimeException2 ()\r
        {\r
-               Directory.GetLastWriteTime ("");\r
+               Directory.GetLastWriteTime (string.Empty);\r
        }\r
        \r
        [Test]\r
@@ -542,7 +630,7 @@ public class DirectoryTest
        [ExpectedException(typeof(ArgumentException))]\r
        public void GetLastWriteTimeUtcException2 ()\r
        {\r
-               Directory.GetLastWriteTimeUtc ("");\r
+               Directory.GetLastWriteTimeUtc (string.Empty);\r
        }\r
        \r
        [Test]\r
@@ -585,7 +673,89 @@ public class DirectoryTest
        }\r
 \r
        [Test]\r
-       public void Move ()\r
+       public void Move_DestDirName_Empty ()\r
+       {\r
+               try {\r
+                       Directory.Move (TempFolder, string.Empty);\r
+                       Assert.Fail ("#A1");\r
+               } catch (ArgumentException ex) {\r
+                       // Empty file name is not legal\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");\r
+                       Assert.IsNull (ex.InnerException, "#A3");\r
+                       Assert.IsNotNull (ex.Message, "#A4");\r
+                       Assert.IsNotNull (ex.ParamName, "#A5");\r
+                       Assert.AreEqual ("destDirName", ex.ParamName, "#A6");\r
+               }\r
+\r
+               try {\r
+                       Directory.Move (TempFolder, "             ");\r
+                       Assert.Fail ("#B1");\r
+               } catch (ArgumentException ex) {\r
+                       // The path is not of a legal form\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");\r
+                       Assert.IsNull (ex.InnerException, "#B3");\r
+                       Assert.IsNotNull (ex.Message, "#B4");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void Move_DestDirName_Null ()\r
+       {\r
+               try {\r
+                       Directory.Move (TempFolder, (string) null);\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentNullException ex) {\r
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNotNull (ex.ParamName, "#5");\r
+                       Assert.AreEqual ("destDirName", ex.ParamName, "#6");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void Move_SourceDirName_Empty ()\r
+       {\r
+               try {\r
+                       Directory.Move (string.Empty, TempFolder);\r
+                       Assert.Fail ("#A1");\r
+               } catch (ArgumentException ex) {\r
+                       // Empty file name is not legal\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");\r
+                       Assert.IsNull (ex.InnerException, "#A3");\r
+                       Assert.IsNotNull (ex.Message, "#A4");\r
+                       Assert.IsNotNull (ex.ParamName, "#A5");\r
+                       Assert.AreEqual ("sourceDirName", ex.ParamName, "#A6");\r
+               }\r
+\r
+               try {\r
+                       Directory.Move ("             ", TempFolder);\r
+                       Assert.Fail ("#B1");\r
+               } catch (ArgumentException ex) {\r
+                       // The path is not of a legal form\r
+                       Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");\r
+                       Assert.IsNull (ex.InnerException, "#B3");\r
+                       Assert.IsNotNull (ex.Message, "#B4");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void Move_SourceDirName_Null ()\r
+       {\r
+               try {\r
+                       Directory.Move ((string) null, TempFolder);\r
+                       Assert.Fail ("#1");\r
+               } catch (ArgumentNullException ex) {\r
+                       Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
+                       Assert.IsNotNull (ex.ParamName, "#5");\r
+                       Assert.AreEqual ("sourceDirName", ex.ParamName, "#6");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void MoveDirectory ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.Test.9";\r
                string path2 = TempFolder + DSC + "DirectoryTest.Test.10";\r
@@ -606,10 +776,10 @@ public class DirectoryTest
                                Directory.Delete (path2 + DSC + "dir", true);\r
                }\r
        }\r
-       \r
+\r
        [Test]\r
-       [ExpectedException(typeof(IOException))]\r
-       public void MoveException1 ()\r
+       [ExpectedException (typeof (IOException))]\r
+       public void MoveDirectory_Same ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.Test.8";\r
                DeleteDirectory (path);\r
@@ -621,28 +791,96 @@ public class DirectoryTest
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentException))]\r
-       public void MoveException2 ()\r
+       public void MoveFile ()\r
        {\r
-               string path = TempFolder + DSC + "DirectoryTest.Test.11";\r
-               DeleteDirectory (path);\r
+               string tempFile1 = Path.Combine (TempFolder, "temp1.txt");\r
+               string tempFile2 = Path.Combine (TempFolder, "temp2.txt");\r
+\r
+               using (StreamWriter sw = File.CreateText (tempFile1)) {\r
+                       sw.Write ("temp1");\r
+               }\r
+               Assert.IsFalse (File.Exists (tempFile2), "#1");\r
+               Directory.Move (tempFile1, tempFile2);\r
+               Assert.IsFalse (File.Exists (tempFile1), "#2");\r
+               Assert.IsTrue (File.Exists (tempFile2), "#3");\r
+               using (StreamReader sr = File.OpenText (tempFile2)) {\r
+                       Assert.AreEqual ("temp1", sr.ReadToEnd (), "#4");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void MoveFile_DestDir_Exists ()\r
+       {\r
+               string tempFile = Path.Combine (TempFolder, "temp1.txt");\r
+               string tempDir = Path.Combine (TempFolder, "temp2");\r
+\r
+               using (StreamWriter sw = File.CreateText (tempFile)) {\r
+                       sw.Write ("temp1");\r
+               }\r
+               Directory.CreateDirectory (tempDir);\r
+\r
                try {\r
-                       Directory.Move ("", path);\r
-               } finally {\r
-                       DeleteDirectory (path);\r
+                       Directory.Move (tempFile, tempDir);\r
+                       Assert.Fail ("#A1");\r
+               } catch (IOException ex) {\r
+                       // Cannot create a file when that file already exists\r
+                       Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");\r
+                       Assert.IsNull (ex.InnerException, "#A3");\r
+                       Assert.IsNotNull (ex.Message, "#A4");\r
                }\r
+\r
+               Assert.IsTrue (File.Exists (tempFile), "#B1");\r
+               Assert.IsFalse (File.Exists (tempDir), "#B2");\r
+               Assert.IsTrue (Directory.Exists (tempDir), "#B3");\r
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(ArgumentException))]\r
-       public void MoveException3 ()\r
+       public void MoveFile_DestFile_Exists ()\r
        {\r
-               string path = TempFolder + DSC + "DirectoryTest.Test.12";\r
-               DeleteDirectory (path);\r
+               string tempFile1 = Path.Combine (TempFolder, "temp1.txt");\r
+               string tempFile2 = Path.Combine (TempFolder, "temp2.txt");\r
+\r
+               using (StreamWriter sw = File.CreateText (tempFile1)) {\r
+                       sw.Write ("temp1");\r
+               }\r
+               using (StreamWriter sw = File.CreateText (tempFile2)) {\r
+                       sw.Write ("temp2");\r
+               }\r
+\r
                try {\r
-                       Directory.Move ("             ", path);\r
-               } finally {\r
-                       DeleteDirectory (path);\r
+                       Directory.Move (tempFile1, tempFile2);\r
+                       Assert.Fail ("#A1");\r
+               } catch (IOException ex) {\r
+                       // Cannot create a file when that file already exists\r
+                       Assert.AreEqual (typeof (IOException), ex.GetType (), "#A2");\r
+                       Assert.IsNull (ex.InnerException, "#A3");\r
+                       Assert.IsNotNull (ex.Message, "#A4");\r
+               }\r
+\r
+               Assert.IsTrue (File.Exists (tempFile1), "#B1");\r
+               using (StreamReader sr = File.OpenText (tempFile1)) {\r
+                       Assert.AreEqual ("temp1", sr.ReadToEnd (), "#B2");\r
+               }\r
+\r
+               Assert.IsTrue (File.Exists (tempFile2), "#C1");\r
+               using (StreamReader sr = File.OpenText (tempFile2)) {\r
+                       Assert.AreEqual ("temp2", sr.ReadToEnd (), "#C2");\r
+               }\r
+       }\r
+\r
+       [Test]\r
+       public void MoveFile_Same ()\r
+       {\r
+               string tempFile = Path.Combine (TempFolder, "temp.txt");\r
+\r
+               try {\r
+                       Directory.Move (tempFile, tempFile);\r
+                       Assert.Fail ("#1");\r
+               } catch (IOException ex) {\r
+                       // Source and destination path must be different\r
+                       Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");\r
+                       Assert.IsNull (ex.InnerException, "#3");\r
+                       Assert.IsNotNull (ex.Message, "#4");\r
                }\r
        }\r
 \r
@@ -681,7 +919,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(IOException))]\r
-       public void MoveException6 ()\r
+       public void MoveDirectory_Dest_SubDir ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.Test.15";\r
                DeleteDirectory (path);\r
@@ -695,8 +933,8 @@ public class DirectoryTest
        }\r
 \r
        [Test]\r
-       [ExpectedException(typeof(IOException))]\r
-       public void MoveException7 ()\r
+       [ExpectedException (typeof (IOException))]\r
+       public void MoveDirectory_Dest_Exists ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.Test.16";\r
                string path2 = TempFolder + DSC + "DirectoryTest.Test.17";\r
@@ -714,15 +952,11 @@ public class DirectoryTest
        }\r
        \r
        [Test]\r
+       [Category("TargetJvmNotSupported")] // CreationTime not supported for TARGET_JVM\r
        public void CreationTime ()\r
        {\r
-               // check for Unix platforms - see FAQ for more details\r
-               // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F\r
-               int platform = (int) Environment.OSVersion.Platform;\r
-               if ((platform == 4) || (platform == 128))\r
-                       // Unix doesnt support CreationTime\r
-                       // FIXME: use Assert.Ignore\r
-                       return;\r
+               if (RunningOnUnix)\r
+                       Assert.Ignore ("Unix doesn't support CreationTime");\r
 \r
                string path = TempFolder + DSC + "DirectoryTest.CreationTime.1";\r
                DeleteDirectory (path);\r
@@ -769,6 +1003,7 @@ public class DirectoryTest
        }\r
 \r
        [Test]\r
+       [Category("TargetJvmNotSupported")] // LastAccessTime not supported for TARGET_JVM\r
        public void LastAccessTime ()\r
        {\r
                string path = TempFolder + DSC + "DirectoryTest.AccessTime.1";\r
@@ -875,7 +1110,7 @@ public class DirectoryTest
        public void SetLastWriteTimeException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetLastWriteTime ("", time);\r
+               Directory.SetLastWriteTime (string.Empty, time);\r
        }\r
        \r
        [Test]\r
@@ -939,7 +1174,7 @@ public class DirectoryTest
        public void SetLastWriteTimeUtcException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetLastWriteTimeUtc ("", time);\r
+               Directory.SetLastWriteTimeUtc (string.Empty, time);\r
        }\r
        \r
        [Test]\r
@@ -990,6 +1225,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeException1 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -998,14 +1234,16 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetLastAccessTime ("", time);\r
+               Directory.SetLastAccessTime (string.Empty, time);\r
        }\r
        \r
        [Test]\r
        [ExpectedException(typeof(FileNotFoundException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeException3 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1020,6 +1258,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeException4 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1028,6 +1267,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeException5 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1053,6 +1293,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeUtcException1 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1061,14 +1302,16 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeUtcException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetLastAccessTimeUtc ("", time);\r
+               Directory.SetLastAccessTimeUtc (string.Empty, time);\r
        }\r
        \r
        [Test]\r
        [ExpectedException(typeof(FileNotFoundException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeUtcException3 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1083,6 +1326,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeUtcException4 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1091,6 +1335,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM\r
        public void SetLastAccessTimeUtcException5 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1115,6 +1360,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeException1 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1123,14 +1369,16 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetCreationTime ("", time);\r
+               Directory.SetCreationTime (string.Empty, time);\r
        }\r
        \r
        [Test]\r
        [ExpectedException(typeof(FileNotFoundException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeException3 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1146,6 +1394,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeException4 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1154,6 +1403,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeException5 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1180,6 +1430,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentNullException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeUtcException1 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1188,14 +1439,16 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeUtcException2 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
-               Directory.SetCreationTimeUtc ("", time);\r
+               Directory.SetCreationTimeUtc (string.Empty, time);\r
        }\r
        \r
        [Test]\r
        [ExpectedException(typeof(FileNotFoundException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeUtcException3 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1212,6 +1465,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeUtcException4 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1220,6 +1474,7 @@ public class DirectoryTest
 \r
        [Test]\r
        [ExpectedException(typeof(ArgumentException))]\r
+       [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM\r
        public void SetCreationTimeUtcException5 ()\r
        {\r
                DateTime time = new DateTime (2003, 4, 6, 6, 4, 2);\r
@@ -1267,6 +1522,24 @@ public class DirectoryTest
                }\r
        }\r
 \r
+       [Test] // bug #346123\r
+       public void GetDirectories_Backslash ()\r
+       {\r
+               if (!RunningOnUnix)\r
+                       // on Windows, backslash is used as directory separator\r
+                       return;\r
+\r
+               string dir = Path.Combine (TempFolder, @"sub\dir");\r
+               Directory.CreateDirectory (dir);\r
+\r
+               Assert.IsTrue (Directory.Exists (dir), "#A1");\r
+               Assert.IsFalse (Directory.Exists (Path.Combine (TempFolder, "dir")), "#A2");\r
+\r
+               string [] dirs = Directory.GetDirectories (TempFolder);\r
+               Assert.AreEqual (1, dirs.Length, "#B1");\r
+               Assert.AreEqual (dir, dirs [0], "#B2");\r
+       }\r
+\r
        [Test]\r
        public void GetParentOfRootDirectory ()\r
        {\r
@@ -1300,6 +1573,128 @@ public class DirectoryTest
                }\r
        }\r
 \r
+       [Test] // bug #346123\r
+       public void GetFiles_Backslash ()\r
+       {\r
+               if (!RunningOnUnix)\r
+                       // on Windows, backslash is used as directory separator\r
+                       return;\r
+\r
+               string file = Path.Combine (TempFolder, @"doc\temp1.file");\r
+               File.Create (file).Close ();\r
+\r
+               Assert.IsTrue (File.Exists (file), "#A1");\r
+               Assert.IsFalse (File.Exists (Path.Combine (TempFolder, "temp1.file")), "#A2");\r
+\r
+               string [] files = Directory.GetFiles (TempFolder);\r
+               Assert.AreEqual (1, files.Length, "#B1");\r
+               Assert.AreEqual (file, files [0], "#B2");\r
+       }\r
+\r
+       [Test] // bug #82212 and bug #325107\r
+       public void GetFiles_Pattern ()\r
+       {\r
+               string [] files = Directory.GetFiles (TempFolder, "*.*");\r
+               Assert.IsNotNull (files, "#A1");\r
+               Assert.AreEqual (0, files.Length, "#A2");\r
+\r
+               string tempFile1 = Path.Combine (TempFolder, "tempFile1");\r
+               File.Create (tempFile1).Close ();\r
+\r
+               files = Directory.GetFiles (TempFolder, "*.*");\r
+               Assert.IsNotNull (files, "#B1");\r
+               Assert.AreEqual (1, files.Length, "#B2");\r
+               Assert.AreEqual (tempFile1, files [0], "#B3");\r
+\r
+               string tempFile2 = Path.Combine (TempFolder, "FileTemp2.tmp");\r
+               File.Create (tempFile2).Close ();\r
+\r
+               files = Directory.GetFiles (TempFolder, "*.*");\r
+               Assert.IsNotNull (files, "#C1");\r
+               Assert.AreEqual (2, files.Length, "#C2");\r
+\r
+               files = Directory.GetFiles (TempFolder, "temp*.*");\r
+               Assert.IsNotNull (files, "#D1");\r
+               Assert.AreEqual (1, files.Length, "#D2");\r
+               Assert.AreEqual (tempFile1, files [0], "#D3");\r
+\r
+               string tempFile3 = Path.Combine (TempFolder, "tempFile3.txt");\r
+               File.Create (tempFile3).Close ();\r
+\r
+               files = Directory.GetFiles (TempFolder, "*File*.*");\r
+               Assert.IsNotNull (files, "#E1");\r
+               Assert.AreEqual (3, files.Length, "#E2");\r
+\r
+               files = Directory.GetFiles (TempFolder, "*File*.tmp");\r
+               Assert.IsNotNull (files, "#F1");\r
+               Assert.AreEqual (1, files.Length, "#F2");\r
+               Assert.AreEqual (tempFile2, files [0], "#F3");\r
+\r
+               files = Directory.GetFiles (TempFolder, "*tempFile*");\r
+               Assert.IsNotNull (files, "#G1");\r
+               Assert.AreEqual (2, files.Length, "#G2");\r
+\r
+               files = Directory.GetFiles (TempFolder, "*tempFile1");\r
+               Assert.IsNotNull (files, "#H1");\r
+               Assert.AreEqual (1, files.Length, "#H2");\r
+               Assert.AreEqual (tempFile1, files [0], "#H3");\r
+\r
+               files = Directory.GetFiles (TempFolder, "*.txt");\r
+               Assert.IsNotNull (files, "#I1");\r
+               Assert.AreEqual (1, files.Length, "#I2");\r
+               Assert.AreEqual (tempFile3, files [0], "#I3");\r
+\r
+               files = Directory.GetFiles (TempFolder, "*.t*");\r
+               Assert.IsNotNull (files, "#J1");\r
+               Assert.AreEqual (2, files.Length, "#J2");\r
+\r
+               files = Directory.GetFiles (TempFolder, "temp*.*");\r
+               Assert.IsNotNull (files, "#K1");\r
+               Assert.AreEqual (2, files.Length, "#K2");\r
+\r
+               File.Delete (tempFile1);\r
+\r
+               files = Directory.GetFiles (TempFolder, "temp*.*");\r
+               Assert.IsNotNull (files, "#L1");\r
+               Assert.AreEqual (1, files.Length, "#L2");\r
+               Assert.AreEqual (tempFile3, files [0], "#L3");\r
+\r
+               files = Directory.GetFiles (TempFolder, ".*");\r
+               Assert.IsNotNull (files, "#M1");\r
+               Assert.AreEqual (0, files.Length, "#M2");\r
+\r
+               string tempFile4 = Path.Combine (TempFolder, "tempFile4.");\r
+               File.Create (tempFile4).Close ();\r
+\r
+               files = Directory.GetFiles (TempFolder, "temp*.");\r
+               Assert.IsNotNull (files, "#N1");\r
+               Assert.AreEqual (1, files.Length, "#N2");\r
+               if (RunningOnUnix)\r
+                       Assert.AreEqual (tempFile4, files [0], "#N3");\r
+               else // on Windows, the trailing dot is automatically trimmed\r
+                       Assert.AreEqual (Path.Combine (TempFolder, "tempFile4"), files [0], "#N3");\r
+       }\r
+\r
+       [Test]\r
+       public void GetFiles_580090 ()\r
+       {\r
+               string cwd = Directory.GetCurrentDirectory ();\r
+               Directory.SetCurrentDirectory (Path.GetTempPath ());\r
+\r
+               string tempFile = Path.Combine (TempFolder, "tempFile.txt");\r
+               File.Create (tempFile).Close ();\r
+\r
+               try {\r
+                       string [] files = Directory.GetFiles (".", TempSubFolder + DSC + "*.t*");\r
+                       Assert.IsNotNull (files, "#J1");\r
+                       Assert.AreEqual (1, files.Length, "#J2");\r
+               }\r
+               finally {\r
+                       Directory.SetCurrentDirectory (cwd);\r
+               }\r
+       }\r
+\r
+\r
        [Test]\r
        [ExpectedException (typeof (ArgumentNullException))]\r
        public void SetCurrentDirectoryNull ()\r
@@ -1329,13 +1724,21 @@ public class DirectoryTest
                dir.GetFiles ("*.nonext");\r
        }\r
 \r
-\r
        [Test]\r
        public void FilenameOnly () // bug 78209\r
        {\r
                Directory.GetParent ("somefile");\r
        }\r
 \r
+       private static bool RunningOnUnix {\r
+               get {\r
+                       // check for Unix platforms - see FAQ for more details\r
+                       // http://www.mono-project.com/FAQ:_Technical#How_to_detect_the_execution_platform_.3F\r
+                       int platform = (int) Environment.OSVersion.Platform;\r
+                       return ((platform == 4) || (platform == 128) || (platform == 6));\r
+               }\r
+       }\r
+\r
        private void DeleteDirectory (string path)\r
        {\r
                if (Directory.Exists (path))\r