Table of Contents

Class JsonPropertyAssertions

Namespace
JsonAssertions.TUnit
Assembly
JsonAssertions.TUnit.dll

Fluent TUnit entry points for asserting the presence or absence of a property at a dot-separated JSON path. Each method is generated into a TUnit assertion chain via the [GenerateAssertion] source generator and delegates to JsonPath in the framework-agnostic core. Both a JSON string and a JsonElement are accepted as the asserted value.

public static class JsonPropertyAssertions
Inheritance
JsonPropertyAssertions
Inherited Members

Remarks

The methods return TUnit.Assertions.Core.AssertionResult so a failure surfaces where on the path resolution stopped (via JsonFailureMessage), not merely that it did. The string overloads parse into a disposable JsonDocument and delegate to the JsonElement overload within the document's lifetime: a JsonElement is only valid while its backing document is alive, and the returned TUnit.Assertions.Core.AssertionResult carries only the already-rendered text.

Methods

DoesNotHaveJsonProperty(string, string)

Asserts the JSON string has no property at the dot-separated path. A malformed JSON string fails the assertion (a body that cannot be parsed must not vacuously satisfy a negative assertion).

[GenerateAssertion]
public static AssertionResult DoesNotHaveJsonProperty(this string json, string path)

Parameters

json string

The JSON document text.

path string

A dot-separated property path, for example user.address.city.

Returns

AssertionResult

DoesNotHaveJsonProperty(JsonElement, string)

Asserts the JSON element has no property at the dot-separated path.

[GenerateAssertion]
public static AssertionResult DoesNotHaveJsonProperty(this JsonElement element, string path)

Parameters

element JsonElement

The JSON element to navigate from.

path string

A dot-separated property path, for example user.address.city.

Returns

AssertionResult

HasJsonProperty(string, string)

Asserts the JSON string has a property at the dot-separated path.

[GenerateAssertion]
public static AssertionResult HasJsonProperty(this string json, string path)

Parameters

json string

The JSON document text.

path string

A dot-separated property path, for example user.address.city.

Returns

AssertionResult

HasJsonProperty(JsonElement, string)

Asserts the JSON element has a property at the dot-separated path.

[GenerateAssertion]
public static AssertionResult HasJsonProperty(this JsonElement element, string path)

Parameters

element JsonElement

The JSON element to navigate from.

path string

A dot-separated property path, for example user.address.city.

Returns

AssertionResult