Skip to main content

aweXpect.Xml

Nuget

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​

ExpectationSubjectSummary
IsEqualTo(…).AsXml()stringis equivalent to the expected XML, by its content
IsValidXmlstringcan be parsed as a well-formed XML document
IsValidXmlMatchingstringis valid XML that matches the expected XML
IsValidXmlMatchingExactlystringis valid XML that matches the expected XML exactly
MatchesXElement, XDocumentcontains the expected XML, ignoring additional nodes
MatchesExactlyXElement, XDocumentis equivalent to the expected XML
HasAttributeXElementhas the attribute, optionally whose value satisfies …
DoesNotHaveAttributeXElementdoes not have the attribute
HasElementXElementhas the child element, optionally which satisfies …
DoesNotHaveElementXElementdoes not have the child element

Documentation​

The full documentation is available at docs.testably.org: