aweXpect.Xml
aweXpect.Xml contains expectations for XML strings and System.Xml.Linq.
At a glance
string xml = """<track title="Let It Be" artist="The Beatles" />""";
// verify that a string is a well-formed XML document
await Expect.That(xml).IsValidXml();
// verify that a string is equal to the expected XML, compared by its content instead of its formatting
await Expect.That(xml).IsEqualTo("""<track artist="The Beatles" title="Let It Be"></track>""").AsXml();
If the element was not closed, i.e. <track title="Let It Be" artist="The Beatles">, the expectation would fail with:
Failure message
Expected that xml
is valid XML,
but it could not be parsed: Unexpected end of file has occurred. The following elements are not closed: track. Line 1, position 47.
Overview
| Expectation | Subject | Summary |
|---|---|---|
IsEqualTo(…).AsXml() | string | is equivalent to the expected XML, by its content |
IsValidXml | string | can be parsed as a well-formed XML document |
IsValidXmlMatching | string | is valid XML that matches the expected XML |
IsValidXmlMatchingExactly | string | is valid XML that matches the expected XML exactly |
Matches | XElement, XDocument | contains the expected XML, ignoring additional nodes |
MatchesExactly | XElement, XDocument | is equivalent to the expected XML |
HasAttribute | XElement | has the attribute, optionally whose value satisfies … |
DoesNotHaveAttribute | XElement | does not have the attribute |
HasElement | XElement | has the child element, optionally which satisfies … |
DoesNotHaveElement | XElement | does not have the child element |
Documentation
The full documentation is available at docs.testably.org:
- XML strings: comparing and validating strings as XML
- Matching XML: matching
XElementandXDocumentagainst an expected XML - Attributes and child elements: verifying single attributes and child elements