arcus-azure / arcus.testing

Reusable testing components used during Arcus testing.
https://testing.arcus-azure.net/
MIT License
4 stars 2 forks source link

`AssertJson`: Add support to ignore node from json path #154

Closed ClementVaillantCodit closed 1 month ago

ClementVaillantCodit commented 1 month ago

Can we add support to ignore node using a Json path syntax? Maybe add a "IgnoreJsonPath" option for that. In the testing framework ignoring of nodes was made this way: Json.Compare(outputStream, expectedOutputStream, out message, new string[] { "$.UnitTestOutputComparison.unittest" });

That would allow a lot more flexibility while comparing.

When I use:

AssertJson.Equal(expectedOutputFileContent, outputFileContent, opt => { 
    opt.IgnoreNode("unittest");
});

with this input:

{
  "unittest": "2",
  "path": {
    "unittest": "2",
    "unittest2": "2",
    "unittest3": "2"
  }
}

I currently have no way to exclude $.path.unittest from the ignored nodes.

Another suggestion, can we rename option IgnoreNode by IgnoreAllNodes, since it traverses the whole tree to exclude this node?

ClementVaillantCodit commented 1 month ago

For now, focus on supporting name, index and wildcard in json path due to limitations in System.Net.Json.

ClementVaillantCodit commented 1 month ago

We won't support that for now, as System.Text.Json does not provide support for JSON path. For now we recommend using Newtonsoft.Json library to remove node from input before executing the comparison. Closed by #163