Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorMike Krüger <mikkrg@microsoft.com>2019-08-09 19:57:08 +0300
committerMike Krüger <mikkrg@microsoft.com>2019-08-15 10:05:55 +0300
commit6c6d3534cf36277f9ecd156dcd55e89211e01763 (patch)
tree0d9ab53ff88678ca7e71f791943a0fbfb7186d70 /main
parent67ce4173797ae3b81a33b5fab69d362e23c9ebe5 (diff)
[UnitTests] Added more FileService unit tests.
Diffstat (limited to 'main')
-rw-r--r--main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs6
-rw-r--r--main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs25
2 files changed, 29 insertions, 2 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
index 09dfa29448..79b0ed3c5a 100644
--- a/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
+++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Core/FileService.cs
@@ -192,7 +192,7 @@ namespace MonoDevelop.Core
/// <param name="path">The path to be checked.</param>
/// <param name="requiredParentDirectory">optional parameter that specifies a required parent of the path.</param>
/// <exception cref="InvalidOperationException">Is thrown when the directory can't be safely deleted.</exception>
- public static void AssertCanDeleteDirectory (FilePath path, string requiredParentDirectory = null)
+ public static void AssertCanDeleteDirectory (FilePath path, string requiredParentDirectory = null, bool canDeleteParent = true)
{
path = path.FullPath.CanonicalPath;
if (lockedDirectories.Contains (path)) {
@@ -206,7 +206,9 @@ namespace MonoDevelop.Core
if (requiredParentDirectory != null) {
var parent = ((FilePath)requiredParentDirectory).FullPath.CanonicalPath;
- if (!parent.IsChildPathOf (path))
+ if (!canDeleteParent && parent == path)
+ throw new InvalidOperationException ("Can't delete parent path" + path);
+ if (!path.IsChildPathOf (parent) && parent != path)
throw new InvalidOperationException (path + " needs to be child of " + requiredParentDirectory);
}
}
diff --git a/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs b/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs
index 132575e471..5d679f7e4b 100644
--- a/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs
+++ b/main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/FileServiceTests.cs
@@ -24,6 +24,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+using System;
using System.Collections.Generic;
using System.IO;
using MonoDevelop.Core;
@@ -176,6 +177,30 @@ namespace MonoDevelop.Projects
void OnFileChanged (object sender, FileEventArgs e)
{
fileChangeEvents.Add (e);
+ }
+
+ [TestCase ("base/child", "base", true)]
+ [TestCase ("/foo", "/foo", true)]
+ [TestCase ("/foo", "/foo", false, ExpectedException = typeof (InvalidOperationException))]
+ [TestCase ("/path/to/child", "/path/to", true)]
+ [TestCase ("base", "other", true, ExpectedException = typeof (InvalidOperationException))]
+ public void CanDeleteFolderWithBaseCheckWorks (string path, string requiredParentDirectory, bool canDeleteParent = true)
+ {
+ FileService.AssertCanDeleteDirectory (path, requiredParentDirectory, canDeleteParent);
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void CantDeleteSystemFolders ()
+ {
+ FileService.AssertCanDeleteDirectory (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData));
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void CantDeleteLogicalDrive ()
+ {
+ FileService.AssertCanDeleteDirectory (Directory.GetLogicalDrives () [0]);
}
}
}