New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BeEquivalentTo does not exclude internal members #1205
Comments
Are you using the |
Not in the posted sample code, but I do use it in my real code. Seems like you are saying that I would like to be able to set an option to include only public members. |
That's the most likely reason. AFAIK, the reflection API does not make a distinction between |
Hmm, I've just ran a test and can confirm this is a bug. FA treats [Fact]
public void When_scenario_it_should_behavior()
{
new Foo
{
InternalProperty = "aa",
PublicProperty = "pp"
}.Should().BeEquivalentTo(new Foo
{
InternalProperty = "bb",
PublicProperty = "pp"
});
}
public class Foo
{
internal string InternalProperty { get; set;}
public string PublicProperty { get; set;}
} After I've changed the implementation of private static PropertyInfo[] GetPublicProperties(Type type)
{
return type.GetProperties(PublicMembersFlag).Where(pi =>
pi.GetGetMethod() != null && !pi.GetGetMethod().IsFamily).ToArray();
} The test passed. cc @jnyrup |
Might be related to #744 |
I would still prefer to be able to choose whether I want to include Don't know what default behavior I would expect. To prevent a breaking change it might be best to compare both By the way: I'd expect the code to only compare |
I found a work-around that only checks public properties: using FluentAssertions.Equivalency;
...
result.Should().BeEquivalentTo(expected, options => options
.Including(info => info.WhichGetterHas(FluentAssertions.Common.CSharpAccessModifier.Public))); |
@jnyrup Is something preventing the solution posted by @dennisdoomen to be implemented in FA? Or do I just have to wait till FA 6.0 comes out? |
Time ;-) |
BeEquivalentTo
fails if aninternal
property has a different value.The documentation, section "Including properties and/or fields" states:
However, it also seems to take into account all
internal
properties and fields.Who is wrong? The documentation or the implementation? What is
BeEquivalentTo
supposed to do?In the following code sample, PrivateMembersShouldNotBeCompared succeeds but InternalMembersShouldNotBeCompared fails on the compare of property
InternalProperty
.The text was updated successfully, but these errors were encountered: