[Tests] Fail with message in case symlink fails
[mono.git] / mcs / class / corlib / Test / System.IO / FileTest.cs
index 6267439aed26efa4406e56557551b5a9a4bd3df5..7e01ce544d7240a073f1ca6fbc32d2cf3cb54c71 100644 (file)
@@ -14,6 +14,8 @@ using System;
 using System.IO;
 using System.Globalization;
 using System.Threading;
+using System.Runtime.InteropServices;
+
 
 using NUnit.Framework;
 
@@ -530,6 +532,12 @@ namespace MonoTests.System.IO
                        }
                }
 
+               [Test]
+               public void Delete_NonExisting_NoException ()
+               {
+                       File.Delete (Path.Combine (Directory.GetDirectoryRoot (Directory.GetCurrentDirectory ()), "monononexistingfile.dat"));
+               }
+
                [Test]
                public void GetAttributes_Archive ()
                {
@@ -812,11 +820,7 @@ namespace MonoTests.System.IO
                                        Assert.AreEqual (typeof (DirectoryNotFoundException), ex.GetType (), "#2");
                                        Assert.IsNull (ex.InnerException, "#3");
                                        Assert.IsNotNull (ex.Message, "#4");
-#if NET_2_0
                                        Assert.IsFalse (ex.Message.IndexOf (destFile) != -1, "#5");
-#else
-                                       Assert.IsTrue (ex.Message.IndexOf (destFile) != -1, "#5");
-#endif
                                }
                        } finally {
                                DeleteFile (sourceFile);
@@ -1107,7 +1111,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void TestGetCreationTime ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "baz";
@@ -1123,7 +1126,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void CreationTime ()
                {
                        if (RunningOnUnix)
@@ -1166,7 +1168,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void LastAccessTime ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "lastAccessTime";
@@ -1261,7 +1262,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTime_Path_Null ()
                {
                        try {
@@ -1276,7 +1276,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTime_Path_Empty ()
                {
                        try {
@@ -1292,13 +1291,11 @@ namespace MonoTests.System.IO
                }
        
                [Test]
-               //[Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTime_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetCreationTime (path);
                        DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
                        Assert.AreEqual (expectedTime.Year, time.Year, "#1");
@@ -1307,22 +1304,9 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
                        Assert.AreEqual (expectedTime.Second, time.Second, "#5");
                        Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetCreationTime (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTime_Path_Whitespace ()
                {
                        try {
@@ -1338,7 +1322,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTime_Path_InvalidPathChars ()
                {
                        try {
@@ -1354,7 +1337,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTimeUtc_Path_Null ()
                {
                        try {
@@ -1369,7 +1351,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTimeUtc_Path_Empty ()
                {
                        try {
@@ -1385,13 +1366,11 @@ namespace MonoTests.System.IO
                }
        
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTimeUtc_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetCreationTimeUtcException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetCreationTimeUtc (path);
                        Assert.AreEqual (1601, time.Year, "#1");
                        Assert.AreEqual (1, time.Month, "#2");
@@ -1399,22 +1378,9 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (0, time.Hour, "#4");
                        Assert.AreEqual (0, time.Second, "#5");
                        Assert.AreEqual (0, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetCreationTimeUtc (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTimeUtc_Path_Whitespace ()
                {
                        try {
@@ -1430,7 +1396,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetCreationTime not supported for TARGET_JVM
                public void GetCreationTimeUtc_Path_InvalidPathChars ()
                {
                        try {
@@ -1446,7 +1411,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTime_Path_Null ()
                {
                        try {
@@ -1461,7 +1425,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTime_Path_Empty ()
                {
                        try {
@@ -1477,13 +1440,11 @@ namespace MonoTests.System.IO
                }
        
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTime_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetLastAccessTime (path);
                        DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
                        Assert.AreEqual (expectedTime.Year, time.Year, "#1");
@@ -1492,22 +1453,9 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
                        Assert.AreEqual (expectedTime.Second, time.Second, "#5");
                        Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetLastAccessTime (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTime_Path_Whitespace ()
                {
                        try {
@@ -1523,7 +1471,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTime_Path_InvalidPathChars ()
                {
                        try {
@@ -1539,7 +1486,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTimeUtc_Path_Null ()
                {
                        try {
@@ -1554,7 +1500,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTimeUtc_Path_Empty ()
                {
                        try {
@@ -1570,13 +1515,11 @@ namespace MonoTests.System.IO
                }
        
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTimeUtc_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetLastAccessTimeUtc (path);
                        Assert.AreEqual (1601, time.Year, "#1");
                        Assert.AreEqual (1, time.Month, "#2");
@@ -1584,22 +1527,9 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (0, time.Hour, "#4");
                        Assert.AreEqual (0, time.Second, "#5");
                        Assert.AreEqual (0, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetLastAccessTimeUtc (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTimeUtc_Path_Whitespace ()
                {
                        try {
@@ -1615,7 +1545,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // GetLastAccessTime not supported for TARGET_JVM
                public void GetLastAccessTimeUtc_Path_InvalidPathChars ()
                {
                        try {
@@ -1665,7 +1594,6 @@ namespace MonoTests.System.IO
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetLastAccessTimeUtcException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetLastWriteTime (path);
                        DateTime expectedTime = (new DateTime (1601, 1, 1)).ToLocalTime ();
                        Assert.AreEqual (expectedTime.Year, time.Year, "#1");
@@ -1674,18 +1602,6 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (expectedTime.Hour, time.Hour, "#4");
                        Assert.AreEqual (expectedTime.Second, time.Second, "#5");
                        Assert.AreEqual (expectedTime.Millisecond, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetLastWriteTime (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
@@ -1753,7 +1669,6 @@ namespace MonoTests.System.IO
                        string path = TempFolder + Path.DirectorySeparatorChar + "GetLastWriteTimeUtcException3";
                        DeleteFile (path);
 
-#if NET_2_0
                        DateTime time = File.GetLastWriteTimeUtc (path);
                        Assert.AreEqual (1601, time.Year, "#1");
                        Assert.AreEqual (1, time.Month, "#2");
@@ -1761,18 +1676,6 @@ namespace MonoTests.System.IO
                        Assert.AreEqual (0, time.Hour, "#4");
                        Assert.AreEqual (0, time.Second, "#5");
                        Assert.AreEqual (0, time.Millisecond, "#6");
-#else
-                       try {
-                               File.GetLastWriteTimeUtc (path);
-                               Assert.Fail ("#1");
-                       } catch (IOException ex) {
-                               // Could not find a part of the path "..."
-                               Assert.AreEqual (typeof (IOException), ex.GetType (), "#2");
-                               Assert.IsNull (ex.InnerException, "#3");
-                               Assert.IsNotNull (ex.Message, "#4");
-                               Assert.IsTrue (ex.Message.IndexOf ("\"" + path + "\"") != -1, "#5");
-                       }
-#endif
                }
 
                [Test]
@@ -1824,7 +1727,6 @@ namespace MonoTests.System.IO
                // SetCreationTime and SetCreationTimeUtc exceptions
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_Path_Null ()
                {
                        try {
@@ -1839,7 +1741,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_Path_Empty ()
                {
                        try {
@@ -1855,7 +1756,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_Path_Whitespace ()
                {
                        try {
@@ -1871,7 +1771,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_Path_InvalidPathChars ()
                {
                        // On Unix there are no invalid path chars.
@@ -1891,7 +1790,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeFileNotFoundException1";
@@ -1927,7 +1825,6 @@ namespace MonoTests.System.IO
 //             }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTime_FileLock ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "CreationTimeIOException1";
@@ -1954,7 +1851,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_Path_Null ()
                { 
                        try {
@@ -1969,7 +1865,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_Path_Empty ()
                {
                        try {
@@ -1985,7 +1880,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_Path_Whitespace ()
                {
                        try {
@@ -2001,7 +1895,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_Path_InvalidPathChars ()
                {
                        // On Unix there are no invalid path chars.
@@ -2021,7 +1914,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcFileNotFoundException1";
@@ -2057,7 +1949,6 @@ namespace MonoTests.System.IO
 //             }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetCreationTime not supported for TARGET_JVM
                public void SetCreationTimeUtc_FileLock ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetCreationTimeUtcIOException1";
@@ -2086,7 +1977,6 @@ namespace MonoTests.System.IO
                // SetLastAccessTime and SetLastAccessTimeUtc exceptions
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_Path_Null ()
                {
                        try {
@@ -2101,7 +1991,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_Path_Empty ()
                {
                        try {
@@ -2117,7 +2006,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_Path_Whitespace ()
                {
                        try {
@@ -2133,7 +2021,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_Path_InvalidPathChars ()
                {
                        // On Unix there are no invalid path chars.
@@ -2153,7 +2040,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeFileNotFoundException1";
@@ -2189,7 +2075,6 @@ namespace MonoTests.System.IO
 //             }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTime_FileLock ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "LastAccessIOException1";
@@ -2216,7 +2101,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTimeUtc_Path_Null ()
                {
                        try {
@@ -2231,7 +2115,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetCLastAccessTimeUtc_Path_Empty ()
                {
                        try {
@@ -2247,7 +2130,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTimeUtc_Path_Whitespace ()
                {
                        try {
@@ -2263,7 +2145,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTimeUtc_Path_InvalidPathChars ()
                {
                        // On Unix there are no invalid path chars.
@@ -2283,7 +2164,6 @@ namespace MonoTests.System.IO
                }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTimeUtc_Path_DoesNotExist ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcFileNotFoundException1";
@@ -2319,7 +2199,6 @@ namespace MonoTests.System.IO
 //             }
 
                [Test]
-               [Category("TargetJvmNotSupported")] // SetLastAccessTime not supported for TARGET_JVM
                public void SetLastAccessTimeUtc_FileLock ()
                {
                        string path = TempFolder + Path.DirectorySeparatorChar + "SetLastAccessTimeUtcIOException1";
@@ -2620,6 +2499,7 @@ namespace MonoTests.System.IO
                }
 
                [Test]
+               [Category ("LargeFileSupport")]
                public void Position_Large ()
                {
                        // fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
@@ -2642,6 +2522,7 @@ namespace MonoTests.System.IO
                }
 
                [Test]
+               [Category ("LargeFileSupport")]
                public void Seek_Large ()
                {
                        // fails if HAVE_LARGE_FILE_SUPPORT is not enabled in device builds
@@ -2666,13 +2547,13 @@ namespace MonoTests.System.IO
                }
 
                [Test]
+               [Category ("LargeFileSupport")]
                public void Lock_Large ()
                {
                        // note: already worked without HAVE_LARGE_FILE_SUPPORT
                        LockUnlock ((long) Int32.MaxValue + 1);
                }
        
-#if NET_2_0
                [Test]
                public void ReadWriteAllText ()
                {
@@ -2726,7 +2607,6 @@ namespace MonoTests.System.IO
                                Assert.AreEqual ("replaceFile", txt, "#3");
                        }
                }
-#endif
 
                static bool RunningOnUnix {
                        get {
@@ -2747,7 +2627,6 @@ namespace MonoTests.System.IO
                                Directory.Delete (path, true);
                }
 
-#if NET_2_0
                void read_all (string s)
                {
                        string f = Path.GetTempFileName ();
@@ -2759,6 +2638,105 @@ namespace MonoTests.System.IO
                                DeleteFile (f);
                        }
                }
-#endif
+
+               void MoveTest (FileAccess acc, FileShare share, bool works)
+               {
+                       // use TEMP so since the default location (right along with the assemblies) 
+                       // will get access denied when running under some environment (e.g. iOS devices)
+                       var file = Path.Combine (Path.GetTempPath (), "kk597rfdnllh89");
+
+                       File.Delete (file + ".old");
+                       using (var v = File.Create (file)) { }
+
+                       using (var stream = new FileStream(file, FileMode.Open, acc, share, 4096, FileOptions.SequentialScan)) {
+                               try {
+                                       File.Move(file, file + ".old");
+                                       if (!works)
+                                               Assert.Fail ("Move with ({0}) and  ({1}) did not fail", acc, share);
+                               } catch (IOException) {
+                                       if (works)
+                                               Assert.Fail ("Move with ({0}) and  ({1}) did fail", acc, share);
+                               }
+                       }
+               }
+
+               [Test]
+               public void MoveTest ()
+               {
+                       MoveTest (FileAccess.Read, FileShare.None, false);
+                       MoveTest (FileAccess.Read, FileShare.Read, false);
+                       MoveTest (FileAccess.Read, FileShare.Write, false);
+                       MoveTest (FileAccess.Read, FileShare.ReadWrite, false);
+                       MoveTest (FileAccess.Read, FileShare.Delete, true);
+                       MoveTest (FileAccess.Read, FileShare.Read | FileShare.Delete, true);
+                       MoveTest (FileAccess.Read, FileShare.Write | FileShare.Delete, true);
+                       MoveTest (FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, true);
+                       MoveTest (FileAccess.Write, FileShare.None, false);
+                       MoveTest (FileAccess.Write, FileShare.Read, false);
+                       MoveTest (FileAccess.Write, FileShare.Write, false);
+                       MoveTest (FileAccess.Write, FileShare.ReadWrite, false);
+                       MoveTest (FileAccess.Write, FileShare.Delete, true);
+                       MoveTest (FileAccess.Write, FileShare.Read | FileShare.Delete, true);
+                       MoveTest (FileAccess.Write, FileShare.Write | FileShare.Delete, true);
+                       MoveTest (FileAccess.Write, FileShare.ReadWrite | FileShare.Delete, true);
+                       MoveTest (FileAccess.ReadWrite, FileShare.None, false);
+                       MoveTest (FileAccess.ReadWrite, FileShare.Read, false);
+                       MoveTest (FileAccess.ReadWrite, FileShare.Write, false);
+                       MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite, false);
+                       MoveTest (FileAccess.ReadWrite, FileShare.Delete, true);
+                       MoveTest (FileAccess.ReadWrite, FileShare.Read | FileShare.Delete, true);
+                       MoveTest (FileAccess.ReadWrite, FileShare.Write | FileShare.Delete, true);
+                       MoveTest (FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, true);
+               }
+
+
+               [DllImport ("libc", SetLastError=true)]
+               public static extern int symlink (string oldpath, string newpath);
+
+               [Test]
+               public void SymLinkLoop ()
+               {
+                       if (!RunningOnUnix)
+                               Assert.Ignore ("Symlink are hard on windows");
+
+                       var name1 = Path.GetRandomFileName ();
+                       var name2 = Path.GetRandomFileName ();
+
+                       var path1 = Path.Combine (Path.GetTempPath (), name1);
+                       var path2 = Path.Combine (Path.GetTempPath (), name2);
+
+                       File.Delete (path1);
+                       File.Delete (path2);
+
+                       try {
+                               if (symlink (path1, path2) != 0)
+                                       Assert.Fail ("symlink #1 failed with errno={0}", Marshal.GetLastWin32Error ());
+                               if (symlink (path2, path1) != 0)
+                                       Assert.Fail ("symlink #2 failed with errno={0}", Marshal.GetLastWin32Error ());
+
+                               Assert.IsTrue (File.Exists (path1), "File.Exists must return true for path1 symlink loop");
+                               Assert.IsTrue (File.Exists (path2), "File.Exists must return true for path2 symlink loop");
+
+                               try {
+                                       using (var f = File.Open (path1, FileMode.Open, FileAccess.Read)) {
+                                               Assert.Fail ("File.Open must throw for symlink loops");
+                                       }
+                               } catch (IOException ex) {
+                                       Assert.AreEqual (0x80070781u, (uint)ex.HResult, "Ensure HRESULT is correct");
+                               }
+
+                               File.Delete (path1); //Delete must not throw and must work
+                               Assert.IsFalse (File.Exists (path1), "File.Delete must delete symlink loops");
+
+                       } finally {
+                               try {
+                                       File.Delete (path1);
+                                       File.Delete (path2);
+                               } catch (IOException) {
+                                       //Don't double fault any exception from the tests.
+                               }
+
+                       }
+               }
        }
 }