public void TestGetAccessControlSections() { var tempLongPathFilename = uncDirectory.Combine(Path.GetRandomFileName()); tempLongPathFilename.CreateDirectory(); try { var di = new DirectoryInfo(tempLongPathFilename); var security = di.GetAccessControl(AccessControlSections.Access); Assert.IsNotNull(security); Assert.AreEqual(typeof(FileSystemRights), security.AccessRightType); Assert.AreEqual(typeof(FileSystemAccessRule), security.AccessRuleType); Assert.AreEqual(typeof(FileSystemAuditRule), security.AuditRuleType); Assert.IsTrue(security.AreAccessRulesCanonical); Assert.IsTrue(security.AreAuditRulesCanonical); Assert.IsFalse(security.AreAccessRulesProtected); Assert.IsFalse(security.AreAuditRulesProtected); var securityGetAccessRules = security.GetAuditRules(true, true, typeof(NTAccount)).Cast <FileSystemAccessRule>(); Assert.AreEqual(0, securityGetAccessRules.Count()); var perm = security.GetAccessRules(true, true, typeof(NTAccount)); var ntAccount = new NTAccount(WindowsIdentity.GetCurrent().Name); var rule = perm.Cast <FileSystemAccessRule>().SingleOrDefault(e => ntAccount == e.IdentityReference); Assert.IsNotNull(rule); Assert.IsTrue((rule.FileSystemRights & FileSystemRights.FullControl) != 0); } finally { Pri.LongPath.Directory.Delete(tempLongPathFilename); } }