I am trying to check the elements of an xml file I generate. I use Fluent Assertions and I am sure there must be a way to assert that "this element exists in the document" by providing only one argument.
For testing purposes, I need to know if some elements are still present or not.
I know I can compare the file with an existing one. Thing is, I know my xml file is not going to be consistent, some elements might be moved or some of their arguments can change. But not all of them.
Let's say this is my xml file:
<tools>
<tool name="AA" description="AhAh">5</tool>
<tool name="BB" description="BBBB" detail="Bexample">15</tool>
<tool name="CC">12</tool>
</tools>
I know the element with name "BB" is not going to be removed in the future I would like to check it this way:
var tools = xml.XPathSelectElements(".//tools//tool");
var containedElement = new XElement("tools")
new XElement("tool", new XAttribute("name", "BB")));
//Here is what I have tried so far
using (new AssertionScope())
{
tools.Should().HaveElement("tool").Which.Should().HaveAttribute("name", "BB");
tools.Should().BeEquivalentTo(containedElement);
tools.Should().ContainEquivalentOf(containedElement);
}
But it seems I cannot check an element without specifying its position in the node if another element before him has the same Element Name.
Message: Expected attribute "name" at "/tool" to have value "BB", but found "AA".
Does anyone has an idea to solve this problem? Thanks for the help