예제 #1
0
        public void TestAttributeMethods()
        {
            SimpleElement se = new SimpleElement();

            Assert.AreEqual(se.Attributes.Count, 0);

            IXmlValue attr1 = se.AddAttribute("attr1");

            attr1.SetString("value1");
            Assert.AreEqual(se.Attributes.Count, 1);

            Assert.IsNull(se.GetAttribute("attr2"));
            Assert.AreEqual(attr1, se.GetAttribute("attr1"));
            Exception e = null;

            try
            {
                se.GetAttribute(null);
            }
            catch (Exception ex)
            {
                e = ex;
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOf(typeof(ArgumentException), e);

            se.AddAttribute("attr2");
            Assert.AreEqual(se.Attributes.Count, 2);
            se.SetAttribute("attr2", null);
            Assert.AreEqual(se.Attributes.Count, 1);
            se.SetAttribute("attr2", new SimpleValue("value2"));
            Assert.AreEqual(se.Attributes.Count, 2);

            Assert.IsNull(se.GetAttribute("attr3"));
            IXmlValue attr3 = se.GetSafeAttribute("attr3");

            Assert.IsNotNull(attr3);
            Assert.IsFalse(attr3.IsMutable);
        }