This NUnit3 Constraint verifies whether the provided XPath expression corresponds to at least one element in the provided object.
All types which are supported by Input.From(object) can be used as input for the object against the constraint is evaluated.
since XMLUnit 2.1.0
Example |
string xml = "<a><b attr=\"abc\"></b></a>"; Assert.That(xml, HasXPathConstraint.HasXPath("//a/b/@attr")); Assert.That(xml, !HasXPathConstraint.HasXPath("//a/b/c")); |
Example |
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"; Assert.That(xmlRootElement, HasXPathConstraint.HasXPath("//atom:feed/atom:entry/atom:id") .WithNamespaceContext(prefix2Uri)); |
See Also: Inherited members from NUnit.Framework.Constraints.Constraint.
|
Creates a {@link HasXPathConstraint} instance with the associated XPath expression. |
override
|
ApplyTo<TActual>
(TActual)Documentation for this section has not yet been entered. |
|
static
|
HasXPath
(string)Creates a constraint that matches when the examined XML input has at least one node corresponding to the specified xPath. |
|
|
WithNamespaceContext
(IDictionary<string, string>)Utility method used for creating a namespace context mapping to be used in XPath matching. |
static
|
Singleton<T>
(this T)An enumerable containing a single element. |
Creates a {@link HasXPathConstraint} instance with the associated XPath expression.Syntax
public HasXPathConstraint (string xPath)Parameters
- xPath
- xPath expression
Remarks
Documentation for this section has not yet been entered.Requirements
Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.9.2.240
Documentation for this section has not yet been entered.Syntax
public override NUnit.Framework.Constraints.ConstraintResult ApplyTo<TActual> (TActual actual)Type Parameters
- TActual
- Documentation for this section has not yet been entered.
Parameters
- actual
- Documentation for this section has not yet been entered.
Returns
Documentation for this section has not yet been entered.Remarks
Documentation for this section has not yet been entered.Requirements
Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.9.2.240
Creates a constraint that matches when the examined XML input has at least one node corresponding to the specified xPath.Syntax
public static HasXPathConstraint HasXPath (string xPath)Parameters
- xPath
- xPath expression
Returns
the xpath constraintRemarks
Documentation for this section has not yet been entered.Example
For example
Example Assert.That(xml, HasXPath("/root/cars[0]/audi"))Requirements
Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.9.2.240
Utility method used for creating a namespace context mapping to be used in XPath matching.Syntax
public HasXPathConstraint WithNamespaceContext (IDictionary<string, string> prefix2Uri)Parameters
- prefix2Uri
- maps from prefix to namespace URI. It is used to resolve XML namespace prefixes in the XPath expression
Returns
Documentation for this section has not yet been entered.Remarks
Documentation for this section has not yet been entered.Requirements
Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.9.2.240