Ejemplo n.º 1
0
        public void TestAddClassByCallback()
        {
            var elements = new HElement[] {
                new HElement("p", "First paragraph."),
                null,
                new HElement("p", new HAttribute("class", "selected class3"), "Second paragraph is selected.")
            };

            elements
            .AddClass((elm, idx) => String.Format("index-{0}", idx))
            ;

            Assert.Equal("index-0", elements[0].Attribute("class").Value);
            Assert.Equal("selected class3 index-2", elements[2].Attribute("class").Value);
        }
Ejemplo n.º 2
0
        public void TestAddClass()
        {
            var elements = new HElement[] {
                new HElement("p", "First paragraph."),
                null,
                new HElement("p", new HAttribute("class", "selected class3"), "Second paragraph is selected.")
            };

            elements
            .AddClass("class1")
            .AddClass("Selected")
            ;
            elements[0].AddClass("more");

            Assert.Equal("class1 Selected more", elements[0].Attribute("class").Value);
            Assert.Equal("selected class3 class1", elements[2].Attribute("class").Value);
        }
Ejemplo n.º 3
0
        public void TestRemoveClass()
        {
            var elements = new HElement[] {
                new HElement("p", "First paragraph."),
                null,
                new HElement("p", new HAttribute("class", "selected class3"), "Second paragraph is selected.")
            };

            elements
            .AddClass("class2")
            .AddClass("Selected")
            .RemoveClass("class2 selected")
            ;


            Assert.Null(elements[0].Attribute("class"));
            Assert.Equal("class3", elements[2].Attribute("class").Value);
        }
Ejemplo n.º 4
0
        public void TestToggleClassByCallback()
        {
            var elements = new HElement[] {
                new HElement("p", new HAttribute("class", "class0"), "First paragraph."),
                null,
                new HElement("p", new HAttribute("class", "selected class3"), "Second paragraph is selected.")
            };

            elements
            .AddClass("class2")
            .AddClass("Selected")
            .ToggleClass((elm, idx) => String.Format("class{0} selected", idx))
            ;

            Assert.Equal("class2", elements[0].Attribute("class").Value);
            Assert.Equal("class3", elements[2].Attribute("class").Value);

            elements
            .ToggleClass((elm, idx) => String.Format("class{0} selected", idx))
            ;

            Assert.Equal("class2 class0 selected", elements[0].Attribute("class").Value);
            Assert.Equal("class3 class2 selected", elements[2].Attribute("class").Value);

            elements
            .ToggleClass((elm, idx) => String.Format("class{0} selected", idx), true)
            ;

            Assert.Equal("class2 class0 selected", elements[0].Attribute("class").Value);
            Assert.Equal("class3 class2 selected", elements[2].Attribute("class").Value);

            elements
            .ToggleClass((elm, idx) => String.Format("class{0} selected", idx), false)
            ;

            Assert.Equal("class2", elements[0].Attribute("class").Value);
            Assert.Equal("class3", elements[2].Attribute("class").Value);
        }