Skip to content

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

@lfritz-seweurodrive

Description

@lfritz-seweurodrive

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