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: Add .count() function to JSON response captures #87

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public static partial class PororocaResponseValueCapturer

foreach (string subpath in subpaths)
{
if (subpath.Equals("count()", StringComparison.InvariantCultureIgnoreCase))
return GetCount(jsonNode);
if (IsArrayElementSubpath(subpath, out string? elementName, out int? index1, out int? index2))
{
if (elementName?.Equals("$", StringComparison.InvariantCultureIgnoreCase) == true)
Expand Down Expand Up @@ -104,4 +106,10 @@ private static bool IsArrayElementSubpath(string subpath, out string? elementNam
return false;
}
}

private static string GetCount(JsonNode node)
{
var count = node.AsArray().Count();
return count.ToString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public static partial class PororocaResponseValueCapturerTests
public static void TestJsonValueCapture(string? expectedCapture, string path, string json) =>
Assert.Equal(expectedCapture, CaptureJsonValue(path, json));

[Theory]
[InlineData("2", "$.count()", testJsonArr)]
[InlineData("3", "$.myObj.myObj2.arr.count()", testJsonObj)]
[InlineData(null, "$.myObj.count()", testJsonObj)]
public static void TestJsonValueCaptureCountFunction(string? expectedCapture, string path, string json) =>
Assert.Equal(expectedCapture, CaptureJsonValue(path, json));

[Theory]
[InlineData("ABC", "/a", "<a>ABC</a>")]
[InlineData("ENG", "/SessionInfo/Language", testXmlSimpleObj)]
Expand Down