Apparently this test should fail but it succeeds!
[TestMethod]
public void Other_should_have_same_props()
{
var first = new
{
Id = 1,
Name = "Bogus",
Title = "Jr"
};
first.Should().NotBeNull()
.And.ShouldHave().SharedProperties().EqualTo(new
{
Id = 2,
Title = "Sr"
});
}
If I strip the first assertion, the test fails as I expect:
first.ShouldHave().SharedProperties().EqualTo(new
{
Id = 2,
Title = "Sr"
});
_Expected property Id to be 2, but found 1._
Is it an expected behavior or bug?
Thanks
Comments: Unfortunately this is the effect of chaining two unrelated assertions. The object.Should().NotBeNull() will return an object of type ObjectAssertions. Since you're chaining this with the property assertions syntax, you are essentially comparing the properties of an ObjectAssertions class. I wouldn't know how to fix this.
[TestMethod]
public void Other_should_have_same_props()
{
var first = new
{
Id = 1,
Name = "Bogus",
Title = "Jr"
};
first.Should().NotBeNull()
.And.ShouldHave().SharedProperties().EqualTo(new
{
Id = 2,
Title = "Sr"
});
}
If I strip the first assertion, the test fails as I expect:
first.ShouldHave().SharedProperties().EqualTo(new
{
Id = 2,
Title = "Sr"
});
_Expected property Id to be 2, but found 1._
Is it an expected behavior or bug?
Thanks
Comments: Unfortunately this is the effect of chaining two unrelated assertions. The object.Should().NotBeNull() will return an object of type ObjectAssertions. Since you're chaining this with the property assertions syntax, you are essentially comparing the properties of an ObjectAssertions class. I wouldn't know how to fix this.