public void ShouldParseSingleElementNameWithNamespace()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("foo:bar");

            Assert.AreEqual(1, names.Count);
            Assert.AreEqual("foo:bar", names[0].FullName);
        }
        public void ShouldParseAttribute()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("@foo");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is AttributeMatch);
        }
        public void ShouldParseRootElement()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("/foo:bar");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is RootElementMatch);
        }
        public void ShouldParseSingleElementName()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("Foo");

            Assert.AreEqual(1, names.Count);
            Assert.AreEqual("Foo", names[0].ToString());
        }
예제 #5
0
        public void MatchSectionCount()
        {
            List <XmlMatch> match = PathExpressionParser.Parse("/configuration/configSections/section");

            int matchCount = 0;

            string xml = @"
<configuration>
  <configSections>
    <section name='foo' />
    <section name='bar' />
  </configSections>
</configuration>";

            XmlReaderSettings set = new XmlReaderSettings();

            set.IgnoreWhitespace = true;
            XmlProcessorReader reader = new XmlProcessorReader(XmlReader.Create(new StringReader(xml)));

            reader.Processors.Add(new XmlPathProcessor(match,
                                                       delegate { matchCount++; },
                                                       reader.NameTable));

            reader.ReadToEnd();

            Assert.AreEqual(2, matchCount);
        }
        public void ShouldParseElementAttributeMatchTogether()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("/foo/bar/@id");

            Assert.AreEqual(2, names.Count);
            Assert.IsTrue(names[0] is RootElementMatch);
            Assert.IsTrue(names[1] is ElementAttributeMatch);
        }
        public void ShouldParseLastElementAsEndElementWithRootStart()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("/foo/bar", MatchMode.EndElement);

            Assert.AreEqual(2, names.Count);
            Assert.IsTrue(names[0] is RootElementMatch);
            Assert.AreEqual(MatchMode.EndElement, ((ElementMatch)names[1]).Mode);
        }
        public void ShouldParseEndElementMode()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("foo:bar", MatchMode.EndElement);

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is ElementMatch);
            Assert.IsTrue(((ElementMatch)names[0]).Mode == MatchMode.EndElement);
        }
        public void ShouldParseAttributeWithPrefix()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("@foo:bar");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is AttributeMatch);
            Assert.AreEqual("foo:bar", names[0].FullName);
        }
        public void ShouldParseWithDescendentOrSelf()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("//foo:bar");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is ElementMatch);
            Assert.IsTrue(((ElementMatch)names[0]).Mode == MatchMode.StartElement);
        }
        public void ShouldParseWildcardName()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("//foo:*");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is XmlNameMatch);
            Assert.IsTrue(((XmlNameMatch)names[0]).IsAnyName);
        }
        public void ShouldParseAttributeWithWildcardNamespace()
        {
            List <XmlMatch> names = PathExpressionParser.Parse("@*:bar");

            Assert.AreEqual(1, names.Count);
            Assert.IsTrue(names[0] is AttributeMatch);
            Assert.IsTrue(((AttributeMatch)names[0]).IsAnyNamespace);
        }
 public void ThrowsIfExpressionNull()
 {
     PathExpressionParser.Parse(null);
 }
 public void ThrowsIfEndElementModeAndAttributeSpecified()
 {
     List <XmlMatch> names = PathExpressionParser.Parse("/foo/bar/@id", MatchMode.EndElement);
 }
 public void ThrowsIfDoubleSlashInExpression()
 {
     List <XmlMatch> names = PathExpressionParser.Parse("/foo//bar/@id");
 }
 public void ThrowsIfAttributePathNotEndExpression()
 {
     List <XmlMatch> names = PathExpressionParser.Parse("/foo/@bar/@id");
 }
 public void ThrowsIfEmptyPrefix()
 {
     List <XmlMatch> names = PathExpressionParser.Parse("/foo/:bar");
 }
 public void ThrowsIfInvalidPath()
 {
     PathExpressionParser.Parse("~");
 }
 public void ThrowsIfExpressionEmptyString()
 {
     PathExpressionParser.Parse(string.Empty);
 }
 public void ThrowsIfEmptyName()
 {
     List <XmlMatch> names = PathExpressionParser.Parse("/foo/bar:/@id");
 }