示例#1
0
        public void TestNullThrowsException()
        {
            XmlTextReader reader = null;

            // ReSharper disable ExpressionIsAlwaysNull
            Assert.Throws <ArgumentNullException>(() => reader.GetAttributes());
            // ReSharper restore ExpressionIsAlwaysNull
        }
示例#2
0
        public void TestNoAttributes()
        {
            using (XmlTextReader reader = new XmlTextReader(new StringReader(@"<Element />")))
            {
                Assert.IsTrue(reader.Read(), "Can't read");
                Assert.IsTrue(reader.Name == "Element", "Not the good tag");
                IDictionary <string, string> attributes = reader.GetAttributes();

                Assert.IsNotNull(attributes, "attributes is null");
                Assert.IsTrue(attributes.Count == 0, "Not the good number of attributes");
                Assert.IsTrue(reader.Name == "Element", "Not back to the element");
            }
        }
示例#3
0
        public void TestAttributes()
        {
            using (XmlTextReader reader = new XmlTextReader(new StringReader(@"<Element a=""123"" b=""458"" c=""azerty"" />")))
            {
                Assert.IsTrue(reader.Read(), "Can't read");
                Assert.IsTrue(reader.Name == "Element", "Not the good tag");
                IDictionary <string, string> attributes = reader.GetAttributes();

                Assert.IsNotNull(attributes, "attributes is null");
                Assert.IsTrue(attributes.Count == 3, "Not the good number of attributes");
                Assert.IsTrue(attributes.ContainsKey("a"), "Has not key a");
                Assert.IsTrue(attributes["a"] == "123", "Value is wrong for key a");
                Assert.IsTrue(attributes.ContainsKey("b"), "Has not key b");
                Assert.IsTrue(attributes["b"] == "458", "Value is wrong for key b");
                Assert.IsTrue(attributes.ContainsKey("c"), "Has not key c");
                Assert.IsTrue(attributes["c"] == "azerty", "Value is wrong for key c");
                Assert.IsTrue(reader.Name == "Element", "Not back to the element");
            }
        }
示例#4
0
 public IDictionary <string, string> GetAttributes()
 {
     return(_parent != null?_parent.GetAttributes() : _reader.GetAttributes());
 }