Пример #1
0
        public void NodeEvent_CreatingModifying()
        {
            ContentType.GetByName("Folder");

            Node node = NodeType.CreateInstance("Folder", _testRoot);

            node.Creating  += new CancellableNodeEventHandler(Node_Creating);
            node.Created   += new EventHandler <NodeEventArgs>(Node_Created);
            node.Modifying += new CancellableNodeEventHandler(Node_Modifying);
            node.Modified  += new EventHandler <NodeEventArgs>(Node_Modified);

            _eventLog = new StringBuilder();
            LoggedTestObserver.ResetLog();

            node.Save();
            node.Index = 2;
            node.Save();

            node.Creating  -= new CancellableNodeEventHandler(Node_Creating);
            node.Created   -= new EventHandler <NodeEventArgs>(Node_Created);
            node.Modifying -= new CancellableNodeEventHandler(Node_Modifying);
            node.Modified  -= new EventHandler <NodeEventArgs>(Node_Modified);

            string cr                = Environment.NewLine;
            string expectedLog       = String.Concat("Node_Creating", cr, "Node_Created", cr, "Node_Modifying", cr, "Node_Modified", cr);
            string expectedStaticLog = String.Concat("TestObserver.OnNodeCreating", cr, "TestObserver.OnNodeCreated", cr, "TestObserver.OnNodeModifying", cr, "TestObserver.OnNodeModified", cr);

            Assert.IsTrue(_eventLog.ToString() == expectedLog, "#1");
            Assert.IsTrue(LoggedTestObserver.GetLog() == expectedStaticLog, "#2");
        }
Пример #2
0
        public void NodeEvent_LongCreationModification()
        {
            string log;

            var content = Content.CreateNew("Car", _testRoot, Guid.NewGuid().ToString());
            var node    = content.ContentHandler;

            LoggedTestObserver.ResetLog();

            content.Save(SavingMode.KeepVersionAndLock);
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "TestObserver.OnNodeCreating\r\n", "#1");

            content = Content.Load(content.Id);
            content.Index++;
            content.Save();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "", "#2");

            content = Content.Load(content.Id);
            content.Index++;
            content.Save();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "", "#3");

            content = Content.Load(content.Id);
            content.CheckIn();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "TestObserver.OnNodeCreated\r\n", "#4");


            content = Content.Load(content.Id);
            content.Index++;
            content["Description"] = "<?xml version='1.0'?><a>b</a>";
            content.Save();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "TestObserver.OnNodeModifying\r\nTestObserver.OnNodeModified\r\n", "#5");
            Assert.AreEqual("<?xml version='1.0'?><a>b</a>", LoggedTestObserver.GetLastDescriptionChanges().Value);


            content = Content.Load(content.Id);
            content.CheckOut();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "TestObserver.OnNodeModifying\r\n", "#6");

            content = Content.Load(content.Id);
            content.Index++;
            content.Save();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "", "#7");

            content = Content.Load(content.Id);
            content.Index++;
            content.Save();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "", "#8");

            content = Content.Load(content.Id);
            content.CheckIn();
            log = LoggedTestObserver.GetLog(); LoggedTestObserver.ResetLog(); Assert.IsTrue(log == "TestObserver.OnNodeModified\r\n", "#9");
        }
Пример #3
0
        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");
        }
Пример #4
0
 public LoggedTestObserver()
 {
     LoggedTestObserver._instance = this;
 }