Skip to content
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

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

Open
mnsc opened this issue Oct 7, 2021 · 1 comment

Comments

@mnsc
Copy link

mnsc commented Oct 7, 2021

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());

@dennisdoomen
Copy link
Member

It's a good suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants