This NUnit3 Constraint verifies whether the evaluation of the provided XPath expression corresponds to the value constraint specified for the provided input XML object.
All types which are supported by Input.From(object)} can be used as input for the XML object against the constraint is evaluated.
since XMLUnit 2.1.0
Example |
final String xml = "<a><b attr=\"abc\"></b></a>"; Assert.That(xml, EvaluateXPathConstraint.HasXPath("//a/b/@attr", Is.EqualTo("abc"))); Assert.That(xml, EvaluateXPathConstraint.HasXPath("count(//a/b/c)", Is.EqualTo("0"))); |
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(xml, EvaluateXPathConstraint.HasXPath("//atom:feed/atom:entry/atom:id/text()", Is.EqualTo("id1")) .WithNamespaceContext(prefix2Uri)); |
See Also: Inherited members from NUnit.Framework.Constraints.Constraint.
|
Creates a Org.XmlUnit.Constraints.EvaluateXPathConstraint instance with the associated XPath expression and the value constraint corresponding to the XPath evaluation. |
override
|
ApplyTo<TActual>
(TActual)Documentation for this section has not yet been entered. |
|
static
|
HasXPath
(string, NUnit.Framework.Constraints.IConstraint)Creates a constraint that matches when the examined XML input has a value at the specified xPath that satisfies the specified valueConstraint. |
|
|
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 Org.XmlUnit.Constraints.EvaluateXPathConstraint instance with the associated XPath expression and the value constraint corresponding to the XPath evaluation.Syntax
public EvaluateXPathConstraint (string xPath, NUnit.Framework.Constraints.IConstraint valueConstraint)Parameters
- xPath
- xPath expression
- valueConstraint
- constraint for the value at the specified xpath
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.3.0.90
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.3.0.90
Creates a constraint that matches when the examined XML input has a value at the specified xPath that satisfies the specified valueConstraint.Syntax
public static EvaluateXPathConstraint HasXPath (string xPath, NUnit.Framework.Constraints.IConstraint valueConstraint)Parameters
- xPath
- xPath expression
- valueConstraint
- constraint for the value at the specified xpath
Returns
the xpath constraintRemarks
Documentation for this section has not yet been entered.Example
For example
Example Assert.That(xml, EvaluateXPathConstraint.HasXPath("//fruits/fruit/@name", Is.EqualTo("apple"))Requirements
Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.3.0.90
Utility method used for creating a namespace context mapping to be used in XPath matching.Syntax
public EvaluateXPathConstraint 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.3.0.90