public void SetDirectoryPermissions() { try { if (!HasFolderPermission) { return; } Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path"); Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory"); Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory"); var permissions = IoDir.GetDirectoryPermission(TestFolder + "//"); Assert.IsTrue(permissions.Any(), "Error getting directory permissions"); IList <FileSystemRights> newPermissions = new List <FileSystemRights>(); foreach (var permission in (FileSystemRights[])System.Enum.GetValues(typeof(FileSystemRights))) { if (permissions.All(p => p != permission)) { newPermissions.Add(permission); } } Assert.IsNotNull(newPermissions, "Error getting permissions"); Assert.IsTrue(newPermissions.Any(), "Error getting permissions"); Console.WriteLine("Permission to set: {0}", string.Join(", ", newPermissions)); var permissionProccessResult = IoDir.SetDirectoryPermissions(TestFolder + "//", newPermissions.ToArray()); if (!permissionProccessResult) { Assert.Inconclusive("Error setting directory permission"); } permissions = IoDir.GetDirectoryPermission(TestFolder + "//"); foreach (var ps in newPermissions) { Assert.IsNotNull(permissions.FirstOrDefault(p => p == ps), "Error setting permission: {0}", ps); } } finally { if (HasFolderPermission) { IoDir.DeleteDirectory(TestFolder + "//"); } } }
public void GetDirectoryPermission() { try { if (!HasFolderPermission) { return; } Assert.IsFalse(IoDir.DirectoryExists(TestFolder + "//"), "Invalid directory path"); Assert.IsTrue(IoDir.CreateDirectory(TestFolder + "//"), "Error creating directory"); Assert.IsTrue(IoDir.DirectoryExists(TestFolder + "//"), "Error creating directory"); Assert.IsTrue(IoDir.GetDirectoryPermission(TestFolder + "//").Any(), "Error getting directory permissions"); } finally { if (HasFolderPermission) { IoDir.DeleteDirectory(TestFolder + "//"); } } }