Show / Hide Table of Contents

Class JsonTestValue

A simple wrapper for a string that can be parsed as JSON for tests.

Inheritance
System.Object
JsonTestValue
Implements
System.IEquatable<JsonTestValue>
Namespace: LaunchDarkly.TestHelpers
Assembly: LaunchDarkly.TestHelpers.dll
Syntax
public sealed class JsonTestValue : ValueType, IEquatable<JsonTestValue>
Remarks

This type provides strong typing so that it is clear when test matchers apply to JSON values versus strings, and hides the implementation details of parsing and serialization which are not relevant to the test logic.

Properties

IsDefined

True if there is a value (that is, the original string was not a null reference).

Declaration
public bool IsDefined { get; }
Property Value
Type Description
System.Boolean

NoValue

Shortcut for creating an undefined value, equivalent to JsonOf(null).

Declaration
public static JsonTestValue NoValue { get; }
Property Value
Type Description
JsonTestValue

Methods

Equals(JsonTestValue)

Compares two values for deep equality.

Declaration
public bool Equals(JsonTestValue other)
Parameters
Type Name Description
JsonTestValue other

another JSON value

Returns
Type Description
System.Boolean

true if the values are deeply equal, or are both undefined

Equals(Object)

Compares two values for deep equality.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

another JSON value

Returns
Type Description
System.Boolean

true if the values are deeply equal, or are both undefined

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

JsonFromValue(Object)

Creates a JsonTestValue by serializing an arbitrary value to JSON.

Declaration
public static JsonTestValue JsonFromValue(object value)
Parameters
Type Name Description
System.Object value

an arbitrary value

Returns
Type Description
JsonTestValue

a JsonTestValue

Remarks

For instance, JsonFromValue(true) is equivalent to JsonOf("true"). This only works for types that are supported by System.Text.Json's default reflection-based serialization mechanism.

JsonOf(String)

Creates a JsonTestValue from a string that should contain JSON.

Declaration
public static JsonTestValue JsonOf(string raw)
Parameters
Type Name Description
System.String raw

the input string

Returns
Type Description
JsonTestValue

a JsonTestValue

Remarks

This method fails immediately for any string that is not well-formed JSON. However, if it is a null reference, it returns an "undefined" instance that will return false from IsDefined.

Exceptions
Type Condition
System.FormatException

for malformed JSON

Property(String)

If this value is a JSON object, return the value of the specified property or an undefined value if there is no such property.

Declaration
public JsonTestValue Property(string name)
Parameters
Type Name Description
System.String name

the property name

Returns
Type Description
JsonTestValue

the value, if any

Exceptions
Type Condition
Xunit.Sdk.XunitException

if the current value is not an object

RequiredProperty(String)

If this value is a JSON object, return the value of the specified property.

Declaration
public JsonTestValue RequiredProperty(string name)
Parameters
Type Name Description
System.String name

the property name

Returns
Type Description
JsonTestValue

the value, if any

Exceptions
Type Condition
Xunit.Sdk.XunitException

if the current value is not an object or it has no such property

ToString()

Returns the JSON as a string, or a "no value" message if undefined.

Declaration
public override string ToString()
Returns
Type Description
System.String

Implements

System.IEquatable<>

See Also

JsonAssertions
In This Article
Back to top Generated by DocFX