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

Commented Unassigned: XElement .Should().Be() gives false positives. [12494]

$
0
0
The current implementation of the Be assertion for XElement is implemented in such a way as to cause apparent false positive tests. It only checks the element names, but other Be() assertions in FluentAssertions tend to work closer to equals.

The following test should not pass, but does because the Be comparison does a name check.

[Test]
public void XElement_Be_Assertion_Should_Be_Deeper()
{
var expected =
new XElement("parent"
, new XElement("child"
, new XElement("grandChild")));

var actual =
new XElement("parent"
, new XElement("child"
, new XElement("grandChild2")));

actual.Should().Be(expected);
}

Either Be (And NotBe) should be hidden/removed for XElement or it should do something a much better check:
Worse case the check would be to call ToString() on both XElements and do a string comparison. The reason I don't just resort to this is that the formatted message for a string comparison is not as helpful as a message catered specifically for XElement might be.
Comments: So what you're suggesting is that we do some kind of deep XML graph comparison?

Viewing all articles
Browse latest Browse all 1402

Trending Articles