Skip to content

Feature request: Adding option to disable strict array ordering for ContainSubtree() #57

@mnsc

Description

@mnsc

I want to assert that a subtree is contained but that the relative ordering of the items in arrays doesn't matter.

To give an example based on the code from the summary.

using FluentAssertions.Json;
void Main()
{
    var json = JToken.Parse("{ id: 1, items: [ { id: 2, type: 'my-type', name: 'Alpha' }, { id: 3, type: 'other-type', name: 'Bravo' } ] }");
    json.Should().ContainSubtree(JToken.Parse("{ items: [ { type: 'my-type', name: 'Alpha' }, { name: 'Bravo' } ] }"));
    json.Should().ContainSubtree(JToken.Parse("{ items: [ { type: 'other-type', name: 'Bravo' }, { name: 'Alpha' } ] }"));
}

This gives an error of item[0] is in the wrong order.

image

I would like to be able to control this behaviour. Eg. have something similar to the options pattern for the main library's BeEquivalentTo?

actual.Should().BeEquivalentTo(expected, options => options.WithoutStrictOrdering());

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions