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
Excluding properties behind an array doesn't work in BeEquivalentTo on collections #1919
Comments
Ahhm... this should be fixed with the next release. See #1782 The new syntax will be: actual.Should().BeEquivalentTo(
expected,
cfg => cfg
.For(a => a.Items)
.Exclude(b => b.Name)); |
Ahhh OK. I did look for existing issues about this but must not have had the right keywords or something. Looking forward to the next release then! |
I cloned the develop branch and tested this (as that PR you referenced was merged) but it doesn't seem to work: var expected = new A[]
{
new A { Items = new List<B> { new B { Name = "Foo" } } }
};
var actual = new A[]
{
new A { Items = new List<B> { new B { Name = "Bar" } } }
};
actual.Should().BeEquivalentTo(
expected,
cfg => cfg.For(a => a.Items).Exclude(b => b.Name)
); This is the exception the test threw:
|
If I was to have a guess at the problem, one difference between my example and the linked PR is that my base type I run |
Hmm.. this have to be a bug then.. |
My PR was about the For my understanding, the following should work on the 6.6.0 release actual.Should().BeEquivalentTo(
expected,
cfg => cfg.Excluding(a => a.Items[0].Name)
); |
Hmm... but what if I want to exclude |
Technically it is both. The code I've inherited uses I think the underlying issue of why |
My point is that even the existing functionality (excluding specific indices) before my PR is not working. Which I think is strange, I guess there are unit tests for this.. |
I initially thought it worked given we have this successful test, but that one is not using a collection at the root. Also, I can confirm the behavior is slightly different when the root is a collection. |
Description
A bit of a weird title but basically if I call
myCollection.Should().BeEquivalent(expected, cfg => cfg.Excluding(i => i.SomeArray[0].SomeProperty))
, the property isn't correctly excluded and I get the follow assertion error:Complete minimal example reproducing the issue
Expected behavior:
The excluding rule to be used and the test to pass.
Actual behavior:
The excluding rule is ignored and the test fails.
Versions
Which version of Fluent Assertions are you using?
v6.6.0
Which .NET runtime and version are you targeting? E.g. .NET framework 4.6.1 or .NET Core 2.1.
.NET 6
Additional Information
I believe this is a regression between v5.5.3 and v6.6.0 - I haven't (yet) nailed down which version but will update when I have.
Edit: The regression starts in v6.0.0. The last v5 has this behaving correctly.
Additionally, this only seems to affect properties behind the array in the excluded check. Properties on the same level as the array work as expected if excluded.
The text was updated successfully, but these errors were encountered: