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 **
<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");