Ejemplo n.º 1
0
        public void CanBeCombinedWithPassingMatcher()
        {
            string xml = "<a><b attr=\"abc\"></b></a>";

            Assert.That(xml, Is.StringContaining("abc")
                        & HasXPathConstraint.HasXPath("//a/b/@attr"));
        }
Ejemplo n.º 2
0
 public void CanBeCombinedWithFailingMatcher()
 {
     Assert.That(() =>
                 Assert.That("foo", Is.StringContaining("bar")
                             & HasXPathConstraint.HasXPath("//a/b/@attr")),
                 Throws.TypeOf <AssertionException>());
 }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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"));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates the result.
 /// </summary>
 public HasXPathConstraintResult(HasXPathConstraint constraint, object actual, IEnumerable <XmlNode> result)
     : base(constraint, actual, result.Count() > 0)
 {
     this.constraint = constraint;
 }
Ejemplo n.º 9
0
 public void QuotesCanBeMixed()
 {
     Assert.That("<a>b'b</a>", HasXPathConstraint.HasXPath("//a[text()=\"b'b\"]"));
 }