Table of Contents

Class JsonEquivalenceAssertions

Namespace
JsonAssertions.TUnit
Assembly
JsonAssertions.TUnit.dll

Fluent TUnit entry points for asserting that a JSON document is structurally equivalent to an expected one. Equivalence is independent of object-property order and of the lexical form of numbers (1, 1.0, and 1e0 are equal); arrays are position-sensitive unless IgnoreArrayOrder() is enabled through the configure callback, and any path registered with IgnorePath(string) is excluded. Each method is generated into a TUnit assertion chain via the [GenerateAssertion] source generator and delegates to JsonEquivalence in the framework-agnostic core. Both a JSON string and a JsonElement are accepted as the asserted value; the expected document is supplied as a JSON string.

public static class JsonEquivalenceAssertions
Inheritance
JsonEquivalenceAssertions
Inherited Members

Methods

IsEquivalentJsonTo(string, string)

Asserts that the JSON string is structurally equivalent to expected.

[GenerateAssertion]
public static AssertionResult IsEquivalentJsonTo(this string actual, string expected)

Parameters

actual string

The actual JSON document text.

expected string

The expected JSON document text.

Returns

AssertionResult

IsEquivalentJsonTo(string, string, Action<JsonEquivalenceOptions>?)

Asserts that the JSON string is structurally equivalent to expected, with comparison options (ignored paths, order-insensitive arrays) set by configure.

[GenerateAssertion]
public static AssertionResult IsEquivalentJsonTo(this string actual, string expected, Action<JsonEquivalenceOptions>? configure)

Parameters

actual string

The actual JSON document text.

expected string

The expected JSON document text.

configure Action<JsonEquivalenceOptions>

A callback that sets comparison options. May be null for the defaults.

Returns

AssertionResult

IsEquivalentJsonTo(JsonElement, string)

Asserts that the JSON element is structurally equivalent to expected.

[GenerateAssertion]
public static AssertionResult IsEquivalentJsonTo(this JsonElement actual, string expected)

Parameters

actual JsonElement

The actual JSON element.

expected string

The expected JSON document text.

Returns

AssertionResult

IsEquivalentJsonTo(JsonElement, string, Action<JsonEquivalenceOptions>?)

Asserts that the JSON element is structurally equivalent to expected, with comparison options (ignored paths, order-insensitive arrays) set by configure.

[GenerateAssertion]
public static AssertionResult IsEquivalentJsonTo(this JsonElement actual, string expected, Action<JsonEquivalenceOptions>? configure)

Parameters

actual JsonElement

The actual JSON element.

expected string

The expected JSON document text.

configure Action<JsonEquivalenceOptions>

A callback that sets comparison options. May be null for the defaults.

Returns

AssertionResult