コード例 #1
0
ファイル: HElementTest.cs プロジェクト: ygrenier/HDocument
        public void TestRemoveAttributes()
        {
            var attr1 = new HAttribute("attr1", "value1");
            var attr2 = new HAttribute("attr2", "value2");
            var attr3 = new HAttribute("attr3", "value3");
            var attr4 = new HAttribute("attr4", "value4");

            // Create parent
            var elm = new HElement("test", attr1, attr2, attr3, attr4);

            Assert.Same(attr1, elm.FirstAttribute);
            Assert.Same(attr4, elm.LastAttribute);

            Assert.Same(elm, attr1.Parent);
            Assert.Null(attr1.PreviousAttribute);
            Assert.Same(attr2, attr1.NextAttribute);

            Assert.Same(elm, attr2.Parent);
            Assert.Same(attr1, attr2.PreviousAttribute);
            Assert.Same(attr3, attr2.NextAttribute);

            Assert.Same(elm, attr3.Parent);
            Assert.Same(attr2, attr3.PreviousAttribute);
            Assert.Same(attr4, attr3.NextAttribute);

            Assert.Same(elm, attr4.Parent);
            Assert.Same(attr3, attr4.PreviousAttribute);
            Assert.Null(attr4.NextAttribute);

            // Remove all attributes
            elm.RemoveAttributes();

            Assert.Null(elm.FirstAttribute);
            Assert.Null(elm.LastAttribute);

            Assert.Null(attr1.Parent);
            Assert.Null(attr1.PreviousAttribute);
            Assert.Null(attr1.NextAttribute);

            Assert.Null(attr2.Parent);
            Assert.Null(attr2.PreviousAttribute);
            Assert.Null(attr2.NextAttribute);

            Assert.Null(attr3.Parent);
            Assert.Null(attr3.PreviousAttribute);
            Assert.Null(attr3.NextAttribute);

            Assert.Null(attr4.Parent);
            Assert.Null(attr4.PreviousAttribute);
            Assert.Null(attr4.NextAttribute);

            Assert.Equal(0, elm.Attributes().Count());

            // Check no exception
            elm.RemoveAttributes();
            Assert.Equal(0, elm.Attributes().Count());
        }