Пример #1
0
        public void CanBeCombinedWithPassingMatcher()
        {
            string xml = "<a><b attr=\"abc\"></b></a>";

            Assert.That(xml, Is.StringContaining("abc")
                        & HasXPathConstraint.HasXPath("//a/b/@attr"));
        }
Пример #2
0
 public void CanBeCombinedWithFailingMatcher()
 {
     Assert.That(() =>
                 Assert.That("foo", Is.StringContaining("bar")
                             & HasXPathConstraint.HasXPath("//a/b/@attr")),
                 Throws.TypeOf <AssertionException>());
 }
Пример #3
0
        public void CreatesAUsefulMessageWhenFailingCombinedWithNot()
        {
            string xml = "<a><b attr=\"abc\"></b></a>";

            Assert.That(() =>
                        Assert.That(xml, !HasXPathConstraint.HasXPath("//a/b/@attr")),
                        Throws.TypeOf <AssertionException>()
                        .With.Property("Message").Contains("not XML with XPath //a/b/@attr"));
        }
Пример #4
0
        public void XPathAttributeIsFound()
        {
            string xml = "<a><b attr=\"abc\"></b></a>";

            Assert.That(xml, HasXPathConstraint.HasXPath("//a/b/@attr"));

            Assert.That(() => Assert.That(xml,
                                          HasXPathConstraint.HasXPath("//a/b[@attr=\"abcd\"]")),
                        Throws.TypeOf <AssertionException>()
                        .With.Property("Message").Contains(" returned no results"));
        }
Пример #5
0
        public void XPathIsFoundInStringWithASingleOccurence()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                         "<feed>" +
                         "   <title>title</title>" +
                         "   <entry>" +
                         "       <title>title1</title>" +
                         "       <id>id1</id>" +
                         "   </entry>" +
                         "</feed>";

            Assert.That(xml, HasXPathConstraint.HasXPath("//feed/entry/id"));
            Assert.That(xml, HasXPathConstraint.HasXPath("//feed/entry/title"));
            Assert.That(xml, !HasXPathConstraint.HasXPath("//feed/entry/description"));
        }
Пример #6
0
        public void XPathIsFoundInDocumentWithASingleOccurence()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                         "<feed>" +
                         "   <title>title</title>" +
                         "   <entry>" +
                         "       <title>title1</title>" +
                         "       <id>id1</id>" +
                         "   </entry>" +
                         "</feed>";

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            var xmlRootElement = doc.DocumentElement;

            Assert.That(xmlRootElement, HasXPathConstraint.HasXPath("entry/id"));
            Assert.That(xmlRootElement, HasXPathConstraint.HasXPath("entry/title"));
            Assert.That(xmlRootElement, !HasXPathConstraint.HasXPath("entry/description"));
        }
Пример #7
0
        public void XPathIsFoundInDocumentWithNamespaceContextWithASingleOccurence()
        {
            string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                         "<feed xmlns=\"http://www.w3.org/2005/Atom\">" +
                         "   <title>title</title>" +
                         "   <entry>" +
                         "       <title>title1</title>" +
                         "       <id>id1</id>" +
                         "   </entry>" +
                         "</feed>";

            var prefix2Uri = new Dictionary <string, string>();

            prefix2Uri["atom"] = "http://www.w3.org/2005/Atom";
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            var xmlRootElement = doc.DocumentElement;

            Assert.That(xmlRootElement, HasXPathConstraint.HasXPath("//atom:feed/atom:entry/atom:id").WithNamespaceContext(prefix2Uri));
            Assert.That(xmlRootElement, HasXPathConstraint.HasXPath("//atom:feed/atom:entry/atom:title").WithNamespaceContext(prefix2Uri));
            Assert.That(xmlRootElement,
                        !HasXPathConstraint.HasXPath("//atom:feed/atom:entry/atom:description").WithNamespaceContext(prefix2Uri));
        }
Пример #8
0
 public void QuotesCanBeMixed()
 {
     Assert.That("<a>b'b</a>", HasXPathConstraint.HasXPath("//a[text()=\"b'b\"]"));
 }