Skip to content

VerifyJson object comparison without order validation (at least for IEnumerable) #1596

@lfritz-seweurodrive

Description

@lfritz-seweurodrive

Note: New issues raised, where it is clear the submitter has not read the issue template, are likely to be closed with "please read the issue template". Please don't take offense at this. It is simply a time management decision. If someone raises an issue, and can't be bothered to spend the time to read the issue template, then the project maintainers should not be expected to spend the time to read the submitted issue. Often too much time is spent going back and forth in issue comments asking for information that is outlined in the issue template.

If you are certain the feature will be accepted, it is better to raise a Pull Request (PR).

If you are uncertain if the feature will be accepted, outline the proposal below to confirm it is viable, prior to raising a PR that implements the feature.

Note that even if the feature is a good idea and viable, it may not be accepted since the ongoing effort in maintaining the feature may outweigh the benefit it delivers.

Is the feature request related to a problem

Yes. Problem which are causing me issues when wanting to use this library.

When comparing JSON using Quibble, currently it is impossible to ignore the order for specific list. This is an issue, as whilst there are lists where the order must be exactly the same, for unordered list this renders comparison difficult.

Why this should be possible:

Imagine a situation where one part of the JSON File differentiates in order with each run, e.g.

(a,b,c)
(b,c,a)
(c,b,a)

Imagine a situation where one part of the JSON File contains a list where one element was removed, but the others unchanged, each with a set of nested properties e.g.

(a: ["mykey: akey", "somevalue: somevalue", ...]), (b: ["mykey: bkey", "somevalue: somevalue", ...]), (c: ["mykey: ckey", "somevalue: somevalue", ...])

when b is removed, I would expect there to be an error - signifying that only b was removed. I would no

Describe the solution

I would like for there to be a flag which can be set as a setting on the VerifierSettings, VerifySettings, Quibbly and finally as attribute.
It should signify, that the ordner is not important for the object being compared.

Alternatively, IEnumerable should by default be handled as unordered, as IEnumerable is an unordered set by dotnet definition per default.
IEnumerable makes no guarantee regarding ordering, whereas the implementation in VerifyTest and Quibbly - assume one was made.

Describe alternatives considered

I tried using a IDictionary, but this does not cover my use case, as it requires the presence of a unique key. And this in turn, defeats the point of having a unordered set. I have multiple elements with similar data, same class being serialized, just differences in e.g. position.

Additional context

I tried creating this for the Quibbly github repo, but the project has been setup in a way which prevents creation of GitHub issues.

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