Quantcast
Channel: Fluent Assertions
Viewing all articles
Browse latest Browse all 1402

Commented Issue: HaveElement doesn't seem to work [12446]

$
0
0
I have a class the produces the following XML...

<Operation Name="Test" Duration="0" />

If I parse the above XML into an XDocument and try to assert like so...

var testDoc = XDocument.Parse(result);
testDoc.Should().HaveElement("Operation");

I get the following error...

Expected XML document <Operation Name=\"Test\" Duration=\"1\" /> to have root element with child <Operation>, but no such child element was found.

If I try parsing it as an XElement like so...

var testElement = XElement.Parse(result);
testElement.Should().HaveElement("Operation");

I get the same error of...

Expected XML element <Operation Name=\"Test\" Duration=\"0\" /> to have child element <Operation>, but no such child element was found.
Comments: ** Comment from web user: Oliwa **

I found the fix. Use HaveRoot on the XDocument like so...

var testDoc = XDocument.Parse(result);
testDoc.Should().HaveRoot("Operation");


Viewing all articles
Browse latest Browse all 1402

Trending Articles