コード例 #1
0
        public void AttrContainerName()
        {
            AttrContainer ac    = new AttrContainer("AttrName", "AttrContainer");
            Attr <string> aName = (Attr <string>)ac.GetAttribute("name");

            Assert.AreEqual("AttrName", aName.Value);
        }
コード例 #2
0
        public void ChangeValueAttr()
        {
            AttrContainer ac    = new AttrContainer("AttrName", "AttrContainer");
            Attr <string> aName = (Attr <string>)ac.GetAttribute("name");

            Assert.AreEqual("AttrName", ((Attr <string>)ac.GetAttribute("name")).Value);
            Assert.AreEqual("AttrName", aName.Value);

            aName.Value = "NewName";

            Assert.AreEqual("NewName", ((Attr <string>)ac.GetAttribute("name")).Value);
            Assert.AreEqual("NewName", aName.Value);
        }
コード例 #3
0
        public void AddAttr()
        {
            AttrContainer ac = new AttrContainer("AttrName", "AttrContainer");

            Attr <string> aString = new Attr <string>("StringAttribute", "value");
            Attr <int>    aInt    = new Attr <int>("IntAttribute", 123);

            ac.AddAttribute(aString);
            ac.AddAttribute(aInt);

            Assert.AreEqual("value", ((Attr <string>)ac.GetAttribute("StringAttribute")).Value);
            Assert.AreEqual(123, ((Attr <int>)ac.GetAttribute("IntAttribute")).Value);
        }
コード例 #4
0
        public void GetAttributeList()
        {
            AttrContainer ac = new AttrContainer("AttrName", "AttrContainer");

            ac.AddAttribute(new Attr <string>("StringAttribute", "value"));
            ac.AddAttribute(new Attr <int>("IntAttribute", 123));

            List <IAttr> list = ac.Attributes.ToList();

            Assert.AreEqual(4, list.Count);
            foreach (IAttr item in list)
            {
                Assert.IsNotNull(item.Name);
                Assert.IsNotNull(item.Type);
            }
        }
コード例 #5
0
        public void AttrContainerOfAttrContainer()
        {
            AttrContainer ac = new AttrContainer("root", "AttrContainer");

            AttrContainer acChild1 = new AttrContainer("Attrchild1", "AttrContainer");
            AttrContainer acChild2 = new AttrContainer("Attrchild2", "AttrContainer");

            ac.AddAttribute(new Attr <AttrContainer>("child1", acChild1));
            ac.AddAttribute(new Attr <AttrContainer>("child2", acChild2));

            Assert.AreEqual("child1", ((Attr <AttrContainer>)ac.GetAttribute("child1")).Name);
            Assert.AreEqual("child2", ((Attr <AttrContainer>)ac.GetAttribute("child2")).Name);

            Assert.AreEqual("Attrchild1", ((ac.GetAttribute("child1") as Attr <AttrContainer>).Value.GetAttribute("name") as Attr <string>).Value);
            Assert.AreEqual("Attrchild2", ((ac.GetAttribute("child2") as Attr <AttrContainer>).Value.GetAttribute("name") as Attr <string>).Value);
        }
コード例 #6
0
        public void AttrContainerSerialization()
        {
            DummySerializer dummySerializer = new DummySerializer();

            AttrContainer ac = new AttrContainer("AttrName", "AttrContainer");

            ac.AddAttribute(new Attr <string>("StringAttribute", "value"));
            ac.AddAttribute(new Attr <int>("IntAttribute", 123));

            using (var file = new TemporaryFile())
            {
                using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(file.FileInfo.FullName))
                {
                    dummySerializer.Deserialize(ac, streamWriter);
                }
            }
        }
コード例 #7
0
ファイル: Element.cs プロジェクト: jogibear9988/AngleSharp
 /// <summary>
 /// Creates a new element node.
 /// </summary>
 internal Element(String name, NodeFlags flags = NodeFlags.None)
     : base(name, NodeType.Element, flags)
 {
     _elements = new HtmlElementCollection(this, deep: false);
     _attributes = new AttrContainer();
 }
コード例 #8
0
        public void DuplicatedKey()
        {
            AttrContainer ac = new AttrContainer("AttrName", "AttrContainer");

            ac.AddAttribute(new Attr <string>("name", "NewName"));
        }
コード例 #9
0
 public void KeyNotFound()
 {
     AttrContainer ac   = new AttrContainer("AttrName", "AttrContainer");
     Attr <int>    aInt = ac.GetAttribute("notFound") as Attr <int>;
 }