Class JsonShapeMatcher

Namespace
ProtoTest.Json
Assembly
ProtoTest.Json.dll
public static class JsonShapeMatcher
Inheritance
JsonShapeMatcher
Inherited Members

Methods

AssertExactMatch(string, object?, JsonSerializerOptions?)

Matches the whole JSON exactly: every field present in the JSON must be mentioned by the expected shape, so the response cannot carry a field the shape does not declare. A value constraint mentions its whole subtree. Every mismatch - including each unmentioned field - is reported at once. Returns the matched property paths.

public static IReadOnlyList<string> AssertExactMatch(string content, object? expected, JsonSerializerOptions? options = null)

Parameters

content string
expected object
options JsonSerializerOptions

Returns

IReadOnlyList<string>

AssertExactMatch(JsonElement, object?, JsonSerializerOptions?)

Matches the whole JSON exactly; see AssertExactMatch(string, object?, JsonSerializerOptions?).

public static IReadOnlyList<string> AssertExactMatch(JsonElement actual, object? expected, JsonSerializerOptions? options = null)

Parameters

actual JsonElement
expected object
options JsonSerializerOptions

Returns

IReadOnlyList<string>

AssertMatch(string, object?, JsonSerializerOptions?)

public static IReadOnlyList<string> AssertMatch(string content, object? expected, JsonSerializerOptions? options = null)

Parameters

content string
expected object
options JsonSerializerOptions

Returns

IReadOnlyList<string>

AssertMatch(JsonElement, object?, JsonSerializerOptions?)

public static IReadOnlyList<string> AssertMatch(JsonElement actual, object? expected, JsonSerializerOptions? options = null)

Parameters

actual JsonElement
expected object
options JsonSerializerOptions

Returns

IReadOnlyList<string>

FindUnmentionedFields(string, IReadOnlyCollection<string>, JsonSerializerOptions?)

The fields of content that mentionedPaths does not cover, in document order and one shallowest path per unmentioned branch. Property names follow the same case rule as matching (PropertyNameCaseInsensitive, case-insensitive by default). Empty content reports nothing; invalid JSON throws JsonDocumentAssertionException like AssertMatch(string, object?, JsonSerializerOptions?).

public static IReadOnlyList<JsonUnmentionedField> FindUnmentionedFields(string content, IReadOnlyCollection<string> mentionedPaths, JsonSerializerOptions? options = null)

Parameters

content string
mentionedPaths IReadOnlyCollection<string>
options JsonSerializerOptions

Returns

IReadOnlyList<JsonUnmentionedField>

FindUnmentionedFields(JsonElement, IReadOnlyCollection<string>, JsonSerializerOptions?)

The fields of actual that mentionedPaths does not cover; see FindUnmentionedFields(string, IReadOnlyCollection<string>, JsonSerializerOptions?).

public static IReadOnlyList<JsonUnmentionedField> FindUnmentionedFields(JsonElement actual, IReadOnlyCollection<string> mentionedPaths, JsonSerializerOptions? options = null)

Parameters

actual JsonElement
mentionedPaths IReadOnlyCollection<string>
options JsonSerializerOptions

Returns

IReadOnlyList<JsonUnmentionedField>