-
Notifications
You must be signed in to change notification settings - Fork 731
Closed
Description
Description
I propose a new feature to exclude certain properties of an object in a nested list. (see: https://stackoverflow.com/questions/22142576/how-to-use-exclude-in-fluentassertions-for-property-in-collection).
Currently, it is only possible to exclude certain properties of an entity at a specified index or to use string-based property path matching. The first one does not offer the required functionality, the latter one is complicated, lacks IntelliSense, and is not straightforward.
Example
Given the following objects, I want to exclude the Text property from the nested collection.
// Arrange
var subject = new
{
Level = new
{
Collection = new[]
{
new { Number = 1, Text = "Actual" },
new { Number = 2, Text = "Actual" }
}
}
};
var expected = new
{
Level = new
{
Collection = new[]
{
new { Number = 1, Text = "Expected" },
new { Number = 2, Text = "Expected" }
}
}
};Proposals
const int MATCH_ALL = 0;
// Option 1: By using a magic constant (Excluding would have to detect if MATCH_ALL was used)
Action option1 = () => subject.Should().BeEquivalentTo(expected,
options => options.Excluding(x => x.Level.Collection[MATCH_ALL].Text));
// Option 2: By using the .Select function on IEnumerable
Action option2 = () => subject.Should().BeEquivalentTo(expected,
options => options.Excluding(x => x.Level.Collection.Select(l => l.Text)));
// Option 3: By using the Excluding function again
Action option3 = () => subject.Should().BeEquivalentTo(expected,
options => options.Excluding(x => x.Level.Collection.Excluding(l => l.Text)));I am also interested in implementing this 🙂
Metadata
Metadata
Assignees
Labels
No labels