Show / Hide Table of Contents

Class JsonAssertions

Test assertions related to JSON.

Inheritance
System.Object
JsonAssertions
Namespace: LaunchDarkly.TestHelpers
Assembly: LaunchDarkly.TestHelpers.dll
Syntax
public class JsonAssertions : Object
Remarks

Examples:

    using static LaunchDarkly.TestHelpers.JsonAssertions;
    using static LaunchDarkly.TestHelpers.JsonTestValue;

    AssertJsonEquals(@"{""a"":1, ""b"":2}", @"{""b"":2, ""a"":1}");
    AssertJsonIncludes(@"{""a"":1}", @"{""b"":2, ""a"":1}");
    AssertJsonEquals(JsonFromValue(true), JsonOf(@"{""a"":true}").Property("a"));

Constructors

JsonAssertions()

Declaration
public JsonAssertions()

Methods

AssertJsonEqual(JsonTestValue, JsonTestValue)

Compares two JSON values for deep equality. If they are unequal, it tries to describe the difference as specifically as possible by recursing into object properties or array elements.

Declaration
public static void AssertJsonEqual(JsonTestValue expected, JsonTestValue actual)
Parameters
Type Name Description
JsonTestValue expected

the expected value

JsonTestValue actual

the actual value

AssertJsonEqual(String, String)

Parses two strings as JSON and compares them for deep equality. If they are unequal, it tries to describe the difference as specifically as possible by recursing into object properties or array elements.

Declaration
public static void AssertJsonEqual(string expected, string actual)
Parameters
Type Name Description
System.String expected

the expected value

System.String actual

the actual value

Exceptions
Type Condition
System.FormatException

for malformed JSON

AssertJsonIncludes(JsonTestValue, JsonTestValue)

Similar to AssertJsonEqual(JsonTestValue, JsonTestValue) except that when comparing JSON objects (at any level) it allows the actual data to contain extra properties that are not in the expected data, and when comparing JSON arrays (at any level) it only checks whether the expected elements appear somewhere in the actual array in any order.

Declaration
public static void AssertJsonIncludes(JsonTestValue expected, JsonTestValue actual)
Parameters
Type Name Description
JsonTestValue expected

the expected value

JsonTestValue actual

the actual value

AssertJsonIncludes(String, String)

Similar to AssertJsonEqual(String, String) except that when comparing JSON objects (at any level) it allows the actual data to contain extra properties that are not in the expected data, and when comparing JSON arrays (at any level) it only checks whether the expected elements appear somewhere in the actual array in any order.

Declaration
public static void AssertJsonIncludes(string expected, string actual)
Parameters
Type Name Description
System.String expected

the expected value

System.String actual

the actual value

In This Article
Back to top Generated by DocFX