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