Ejemplo n.º 1
0
        public void AttributeSelector_ForQualifiedName_WithValueIsLanguageCode()
        {
            var selector = CssSelector.WithAttribute("href", "x", CssAttributeMatchOperator.LanguageCode, "fr");

            Assert.Multiple(() =>
            {
                Assert.That(selector, Is.InstanceOf <CssSimpleSelector>());
                Assert.That(selector.LocalName, Is.EqualTo("href"), nameof(selector.LocalName));
                Assert.That(selector.NamespacePrefix, Is.EqualTo("x"), nameof(selector.NamespacePrefix));
                Assert.That(selector.MatchOperator, Is.EqualTo(CssAttributeMatchOperator.LanguageCode), nameof(selector.MatchOperator));
                Assert.That(selector.MatchOperand, Is.EqualTo("fr"), nameof(selector.MatchOperand));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(0, 1, 0)), nameof(selector.Specificity));
            });
        }
Ejemplo n.º 2
0
        public void AttributeSelector_ForNameInAnyNamespace_WithValueContainingWord()
        {
            var selector = CssSelector.WithAttribute("href", "*", CssAttributeMatchOperator.ContainsWord, "test");

            Assert.Multiple(() =>
            {
                Assert.That(selector, Is.InstanceOf <CssSimpleSelector>());
                Assert.That(selector.LocalName, Is.EqualTo("href"), nameof(selector.LocalName));
                Assert.That(selector.NamespacePrefix, Is.EqualTo("*"), nameof(selector.NamespacePrefix));
                Assert.That(selector.MatchOperator, Is.EqualTo(CssAttributeMatchOperator.ContainsWord), nameof(selector.MatchOperator));
                Assert.That(selector.MatchOperand, Is.EqualTo("test"), nameof(selector.MatchOperand));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(0, 1, 0)), nameof(selector.Specificity));
            });
        }
Ejemplo n.º 3
0
        public void AttributeSelector_ForNameInUnspecifiedNamespace()
        {
            var selector = CssSelector.WithAttribute("href");

            Assert.Multiple(() =>
            {
                Assert.That(selector, Is.InstanceOf <CssSimpleSelector>());
                Assert.That(selector.LocalName, Is.EqualTo("href"), nameof(selector.LocalName));
                Assert.That(selector.NamespacePrefix, Is.Null, nameof(selector.NamespacePrefix));
                Assert.That(selector.MatchOperator, Is.EqualTo(CssAttributeMatchOperator.Any), nameof(selector.MatchOperator));
                Assert.That(selector.MatchOperand, Is.Null, nameof(selector.MatchOperand));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(0, 1, 0)), nameof(selector.Specificity));
            });
        }
Ejemplo n.º 4
0
        public void AttributeSelector_ForNameWithoutNamespace_WithExactValue()
        {
            var selector = CssSelector.WithAttribute("href", "", CssAttributeMatchOperator.Exact, "#some-target");

            Assert.Multiple(() =>
            {
                Assert.That(selector, Is.InstanceOf <CssSimpleSelector>());
                Assert.That(selector.LocalName, Is.EqualTo("href"), nameof(selector.LocalName));
                Assert.That(selector.NamespacePrefix, Is.EqualTo(""), nameof(selector.NamespacePrefix));
                Assert.That(selector.MatchOperator, Is.EqualTo(CssAttributeMatchOperator.Exact), nameof(selector.MatchOperator));
                Assert.That(selector.MatchOperand, Is.EqualTo("#some-target"), nameof(selector.MatchOperand));
                Assert.That(selector.Specificity, Is.EqualTo(new CssSpecificity(0, 1, 0)), nameof(selector.Specificity));
            });
        }
Ejemplo n.º 5
0
        public void AttributeSelector_ForNameWithoutNamespace_WithExactValue_Matches()
        {
            var selector = CssSelector.WithAttribute("href", "", CssAttributeMatchOperator.Exact, "#another-target");
            var xdoc     = XDocument.Parse(@"
				<html>
					<head />
					<body>
						<a id='anchor1' href='#some-target' />
						<a id='anchor2' href='#another-target' />
					</body>
				</html>"                );

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "anchor2" }));
        }
Ejemplo n.º 6
0
        public void AttributeSelector_ForNameWithoutNamespace_WithAnyValue_Matches()
        {
            var selector = CssSelector.WithAttribute("href", "");
            var xdoc     = XDocument.Parse(@"
				<html>
					<head />
					<body>
						<a id='anchor1' href='http://some.where.else' />
						<a id='anchor2' />
					</body>
				</html>"                );

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "anchor1" }));
        }
Ejemplo n.º 7
0
        public void AttributeSelector_ForNameInAnyNamespace_WithAnyValue_Matches()
        {
            var selector = CssSelector.WithAttribute("href", "*");
            var xdoc     = XDocument.Parse(string.Format(@"
				<html xmlns:s='{0}' xmlns:t='{1}'>
					<head />
					<body>
						<a id='anchor1' href='#some-target' />
						<a id='anchor2' s:href='#another-target' />
						<a id='anchor3' />
					</body>
				</html>"                , XHTML_NAMESPACE, SOME_NAMESPACE));

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "anchor1", "anchor2" }));
        }
Ejemplo n.º 8
0
        public void AttributeSelector_ForLocalNameInAnyNamespace_WithValueContainingWord_Matches()
        {
            var selector = CssSelector.WithAttribute("href", "*", CssAttributeMatchOperator.ContainsWord, "test");
            var xdoc     = XDocument.Parse(string.Format(@"
				<html xmlns:s='{0}' xmlns:t='{1}'>
					<head />
					<body>
						<a id='anchor1' href='blurb' />
						<a id='anchor2' s:href='blurb with test' />
						<a id='anchor3' t:href='test' />
						<a id='anchor4' t:href='a test too' />
						<a id='anchor5' t:href='more tests' />
						<a id='anchor6' />
					</body>
				</html>"                , XHTML_NAMESPACE, SOME_NAMESPACE));

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "anchor2", "anchor3", "anchor4" }));
        }
Ejemplo n.º 9
0
        public void AttributeSelector_ForQualifiedName_WithValueIsLanguageCode_Matches()
        {
            _namespaceManager.AddNamespace("x", XHTML_NAMESPACE);
            _namespaceManager.AddNamespace("s", SOME_NAMESPACE);

            var selector = CssSelector.WithAttribute("lang", "x", CssAttributeMatchOperator.LanguageCode, "fr");
            var xdoc     = XDocument.Parse(string.Format(@"
				<html xmlns:x='{0}' xmlns:s='{1}'>
					<head />
					<body>
						<a id='anchor1' x:lang='nl' />
						<a id='anchor2' x:lang='fr' />
						<a id='anchor3' x:lang='french' />
						<a id='anchor4' x:lang='fr-FR' />
						<a id='anchor5' x:lang='-fr' />
						<a id='anchor6' s:lang='fr' />
						<a id='anchor7' />
					</body>
				</html>"                , XHTML_NAMESPACE, SOME_NAMESPACE));

            var matchingElements = Match(xdoc, selector);

            Assert.That(matchingElements.Select(e => e.Attribute("id").Value), Is.EquivalentTo(new[] { "anchor2", "anchor4" }));
        }
Ejemplo n.º 10
0
        public void AttributeSelector_ForQualifiedName_WithValueIsLanguageCode_ToString()
        {
            var selector = CssSelector.WithAttribute("lang", "x", CssAttributeMatchOperator.LanguageCode, "fr");

            Assert.That(selector.ToString(), Is.EqualTo("[x|lang|=\"fr\"]"));
        }
Ejemplo n.º 11
0
 public void AttributeSelector_ForQualifiedName_WithAnyValue_ToString()
 {
     Assert.That(CssSelector.WithAttribute("href", "x").ToString(), Is.EqualTo("[x|href]"));
 }
Ejemplo n.º 12
0
        public void AttributeSelector_ForNameInAnyNamespace_WithValueContainingWord_ToString()
        {
            var selector = CssSelector.WithAttribute("href", "*", CssAttributeMatchOperator.ContainsWord, "test");

            Assert.That(selector.ToString(), Is.EqualTo("[*|href~=\"test\"]"));
        }
Ejemplo n.º 13
0
        public void AttributeSelector_ForNameInAnyNamespace_WithAnyValue_ToString()
        {
            var selector = CssSelector.WithAttribute("href", "*");

            Assert.That(selector.ToString(), Is.EqualTo("[*|href]"));
        }
Ejemplo n.º 14
0
        public void AttributeSelector_ForNameWithoutNamespace_WithExactValue_ToString()
        {
            var selector = CssSelector.WithAttribute("href", "", CssAttributeMatchOperator.Exact, "#some-target");

            Assert.That(selector.ToString(), Is.EqualTo("[|href=\"#some-target\"]"));
        }