コード例 #1
0
ファイル: NodeEventTest.cs プロジェクト: kimduquan/DMIS
        public void NodeEvent_PermissionChanging()
        {
            var content = Content.CreateNew("Car", _testRoot, Guid.NewGuid().ToString());

            content.Save();

            var expectedLog = String.Concat("TestObserver.OnPermissionChanging", Environment.NewLine, "TestObserver.OnPermissionChanged", Environment.NewLine);

            //---- 1
            LoggedTestObserver.ResetLog();
            content.Security.BreakInheritance();
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#1");

            //---- 2
            LoggedTestObserver.ResetLog();
            content.Security.SetPermission(Group.Everyone, true, PermissionType.RunApplication, PermissionValue.Allow);
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#2");

            //---- 3
            LoggedTestObserver.ResetLog();
            content.Security.SetPermissions(Group.Everyone.Id, true, new[] { PermissionValue.Allow, PermissionValue.Allow, PermissionValue.Allow, PermissionValue.Allow });
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#3");

            //---- 4
            LoggedTestObserver.ResetLog();
            content.Security.SetAcl(content.Security.GetAcl());
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#4a");
            LoggedTestObserver.ResetLog();
            SecurityHandler.SetAcl(content.Security.GetAcl(), content.Id);
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#4b");
            LoggedTestObserver.ResetLog();
            SecurityHandler.SetAcl(content.Security.GetAcl(), content.Path);
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#4c");

            //---- 5
            content = Content.Load(content.Id);
            LoggedTestObserver.ResetLog();
            content.Security.RemoveBreakInheritance();
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#5");

            //---- 6
            var sb       = new StringBuilder();
            var settings = new XmlWriterSettings {
                Indent = true, IndentChars = "  "
            };

            using (var xmlWriter = XmlWriter.Create(sb, settings))
            {
                xmlWriter.WriteStartDocument();
                xmlWriter.WriteStartElement("Permissions");
                content.Security.ExportPermissions(xmlWriter);
                xmlWriter.WriteEndElement();
                xmlWriter.WriteEndDocument();
            }

            var xml = new XmlDocument();

            xml.LoadXml(sb.ToString());
            var permissionNode = xml.DocumentElement;

            LoggedTestObserver.ResetLog();
            content.Security.ImportPermissions(permissionNode, "####");

            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#6");

            //---- 7
            LoggedTestObserver.ResetLog();
            content.Security.RemoveExplicitEntries();
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedLog, "#7");
        }