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: Replaced by https://github.com/dennisdoomen/fluentassertions/issues/3
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: Replaced by https://github.com/dennisdoomen/fluentassertions/issues/3