示例#1
0
        public void AddStoragePermissionsTest()
        {
            string        identity = Environment.UserDomainName + "\\" + Environment.UserName;
            DirectoryInfo di       = new DirectoryInfo(Constants.Directory);

            Memba.Tests.Memba_Install_WebInstallerAccessor.AddStoragePermissions(identity, di);

            //Check
            DirectorySecurity           ds       = di.GetAccessControl();
            AuthorizationRuleCollection colRules = ds.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount));

            System.Collections.IEnumerator objEnumerator = colRules.GetEnumerator();
            bool bFound = false;

            while (objEnumerator.MoveNext())
            {
                AuthorizationRule objRule = objEnumerator.Current as AuthorizationRule;
                if (objRule.IdentityReference.Value.Equals(identity))
                {
                    bFound = true;
                }
            }
            Assert.IsTrue(bFound);

            //Rollback
            ds.RemoveAccessRule(new FileSystemAccessRule(identity, FileSystemRights.Modify, AccessControlType.Allow));
#if (DEBUG)
            colRules      = ds.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount));
            objEnumerator = colRules.GetEnumerator();
            while (objEnumerator.MoveNext())
            {
                AuthorizationRule objRule = objEnumerator.Current as AuthorizationRule;
                if (objRule.IdentityReference.Value.Equals(identity))
                {
                    Assert.Fail("Cannot rollback");
                }
            }
#endif
        }