Table of Contents

Class JsonContainsAssertions

Namespace
JsonAssertions.TUnit
Assembly
JsonAssertions.TUnit.dll

Fluent TUnit entry points for asserting that a JSON document contains an expected subset: every property in the expected document must be present in the actual document with an equivalent value (recursively), while the actual document may carry additional properties. This is the subset counterpart of IsEquivalentJsonTo(string, string) (full equality); it collapses a block of per-property HasJsonProperty / HasJsonValue checks into one declarative assertion whose failure lists every field that is missing or wrong. Matching is independent of object-property order and of the lexical form of numbers (1, 1.0, and 1e0 are equal); an expected array asserts a positional prefix (the actual array may be longer) 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 ContainsAll(JsonElement, JsonElement, JsonEquivalenceOptions) in the framework-agnostic core. Both a JSON string and a JsonElement are accepted as the asserted value; the expected subset is supplied as a JSON string.

public static class JsonContainsAssertions
Inheritance
JsonContainsAssertions
Inherited Members

Methods

ContainsJson(string, string)

Asserts that the JSON string contains expectedSubset as a subset.

[GenerateAssertion]
public static AssertionResult ContainsJson(this string actual, string expectedSubset)

Parameters

actual string

The actual JSON document text.

expectedSubset string

The expected subset document text.

Returns

AssertionResult

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

Asserts that the JSON string contains expectedSubset as a subset, with comparison options (ignored paths, order-insensitive arrays) set by configure.

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

Parameters

actual string

The actual JSON document text.

expectedSubset string

The expected subset document text.

configure Action<JsonEquivalenceOptions>

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

Returns

AssertionResult

ContainsJson(JsonElement, string)

Asserts that the JSON element contains expectedSubset as a subset.

[GenerateAssertion]
public static AssertionResult ContainsJson(this JsonElement actual, string expectedSubset)

Parameters

actual JsonElement

The actual JSON element.

expectedSubset string

The expected subset document text.

Returns

AssertionResult

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

Asserts that the JSON element contains expectedSubset as a subset, with comparison options (ignored paths, order-insensitive arrays) set by configure.

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

Parameters

actual JsonElement

The actual JSON element.

expectedSubset string

The expected subset document text.

configure Action<JsonEquivalenceOptions>

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

Returns

AssertionResult