Skip to content

Idea for new collection assertion #1480

@vanya-lebedev

Description

@vanya-lebedev

Hello, fluentassertions community,

I would like to propose a new overload of the BeEquivalentTo method for collection assertions. Here's an example:

plannedOrders.Should().BeEquivalentTo(
    order => order.Type == OrderType.Purchase && order.Quantity == 5 && order.Date == tomorrow,
    order => order.Type == OrderType.Transfer && order.SourceLocation == distributionCenter && order.Quantity == 3 && order.Date == today,
    order => order.Type == OrderType.Transfer && order.SourceLocation == factory && order.Quantity == 5 && order.Date == today.AddDays(10)
);

Basically, the API should be similar to the existing collection.Should().BeEquivalentTo() API but instead of providing a collection of elements as input we would instead provide a collection of predicates that elements of the collection must match. Assertion should pass if it is possible to have a 1-1 mapping between elements of the collection and the predicates.

The proposed API is useful in scenarios when the collection has elements with many properties but only few of these are insteresting in the scope of a given test scenario.

Could you please let me know if there is interest in the community in this feature? I would be happy to contribute.

Best regards,
Vanya

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions