xmlunit-nunit3-constraints : Org.XmlUnit.Constraints Namespace

HasXPathConstraint Class

This NUnit3 Constraint verifies whether the provided XPath expression corresponds to at least one element in the provided object.

Syntax

public class HasXPathConstraint : NUnit.Framework.Constraints.Constraint

Remarks

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

Simple Example
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

Example with namespace mapping
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));
            

Requirements

Namespace: Org.XmlUnit.Constraints
Assembly: xmlunit-nunit3-constraints (in xmlunit-nunit3-constraints.dll)
Assembly Versions: 2.9.2.240

Members

See Also: Inherited members from NUnit.Framework.Constraints.Constraint.

Public Constructors

Creates a {@link HasXPathConstraint} instance with the associated XPath expression.

Public Methods

override
ApplyTo<TActual> (TActual) : NUnit.Framework.Constraints.ConstraintResult
Documentation for this section has not yet been entered.
static
HasXPath (string) : HasXPathConstraint
Creates a constraint that matches when the examined XML input has at least one node corresponding to the specified xPath.
WithNamespaceContext (IDictionary<string, string>) : HasXPathConstraint
Utility method used for creating a namespace context mapping to be used in XPath matching.

Extension Methods

static
Singleton<T> (this T) : IEnumerable<T>
An enumerable containing a single element.

Member Details

HasXPathConstraint Constructor

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

ApplyTo<TActual> Generic Method

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

HasXPath Method

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 constraint

Remarks

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

WithNamespaceContext Method

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