How to compare XDocument while ignoring the order of elements. #1925
-
Hi ✌️ I'm trying to compare two using System.Xml.Linq;
using FluentAssertions;
using FluentAssertions.Execution;
const string expectedXml = @"
<root>
<a></a>
<b></b>
<c></c>
</root>
";
const string actualXml = @"
<root>
<b></b>
<a></a>
<c></c>
</root>
";
var actual = XDocument.Parse(actualXml);
var expected = XDocument.Parse(expectedXml);
actual.Should().BeEquivalentTo(expected); // throws I was hopping to have the same behavior as the collection form of My question is : is there an elegant way of testing this ? I thought of somehow manually ordering all the elements, but it might take a while for large documents. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
BeEquivalentTo
uses it own implementation instead ofXNode.DeepEquals
to verify equivalency. But since the order of elements in XML is significant, we decided to respect that aspect of XML.