public void ObserveAttributes_should_invoke_optimized_registration()
        {
            var doc = new DomDocument();

            doc.AppendElement("hello").AppendElement("world");

            var evts     = new TestActionDispatcher <DomAttributeEvent>(_ => {});
            var observer = doc.ObserveAttributes(doc.DocumentElement, "l", evts.Invoke, DomScope.TargetAndDescendants);

            doc.QuerySelectorAll("*").Attribute("l", "k");
            Assert.Equal(2, evts.CallCount);
            Assert.Equal("hello", evts.ArgsForCall(0).Target.LocalName);
            Assert.Equal("world", evts.ArgsForCall(1).Target.LocalName);
            Assert.Equal("l", evts.ArgsForCall(1).LocalName);
        }
        public void ObserveAttributes_callback_should_be_invoked_on_removing_an_attribute(Action <DomElement> callback)
        {
            var doc = new DomDocument().LoadXml(@"
                <root attr='root value' />
            ".Replace("'", "\""));

            var element = doc.QuerySelector("root");

            var evts = new TestActionDispatcher <DomAttributeEvent>(_ => {});

            doc.ObserveAttributes(element, evts.Invoke);

            callback(element);

            Assert.Equal(1, evts.CallCount);
            Assert.Equal("root value", evts.ArgsForCall(0).OldValue);
            Assert.Null(evts.ArgsForCall(0).Value);
            Assert.Equal("attr", evts.ArgsForCall(0).LocalName);
        }
Exemple #3
0
        public void GetName_will_notify_mutation_events_when_name_content_changes()
        {
            var ele = new DomDocument().CreateElement("s");

            ele.NameContext = DomNameContext.Xml;
            ele.Attribute("a", "a").Attribute("A", "A")
            .Attribute("b", "b").Attribute("B", "B")
            .Attribute("c", "c").Attribute("C", "C");

            var evts     = new TestActionDispatcher <DomAttributeEvent>(_ => {});
            var observer = ele.OwnerDocument.ObserveAttributes(ele, evts.Invoke);

            ele.NameContext = DomNameContext.Html;

            // Should have generated several events indicating that attributes were
            Assert.Equal(3, evts.CallCount);
            Assert.Equal("A", evts.ArgsForCall(0).LocalName);
            Assert.Equal("B", evts.ArgsForCall(1).LocalName);
            Assert.Equal("C", evts.ArgsForCall(2).LocalName);
        }
        public void ObserveChildNodes_callback_should_be_invoked_on_mutation_nodes(MutationData data)
        {
            var doc = new DomDocument().LoadXml(@"
                <root><a/><b/><c/></root>
            ");

            var element  = doc.DocumentElement;
            var evts     = new TestActionDispatcher <DomMutationEvent>(_ => {});
            var expected = data.Event(element);

            doc.ObserveChildNodes(element, evts.Invoke);

            data.Action(element);
            var actuallyAddedNodes = data.Event(element).AddedNodes;

            Assert.Equal(1, evts.CallCount);
            Assert.Equal(actuallyAddedNodes.NodeNames(), evts.ArgsForCall(0).AddedNodes.NodeNames());
            Assert.Equal(expected.RemovedNodes.NodeNames(), evts.ArgsForCall(0).RemovedNodes.NodeNames());
            Assert.Same(expected.NextSiblingNode, evts.ArgsForCall(0).NextSiblingNode);
            Assert.Same(expected.PreviousSiblingNode, evts.ArgsForCall(0).PreviousSiblingNode);
        }