Class ProtoMessage

Namespace
ProtoTest.Messaging
Assembly
ProtoTest.Messaging.dll

A message observed on or sent to a broker. Adapters map their technology's message onto this shape; the test-side API and the trace never see a broker-specific type.

public sealed record ProtoMessage : IEquatable<ProtoMessage>
Inheritance
ProtoMessage
Implements
Inherited Members
Extension Methods

Constructors

ProtoMessage(string, string?, IReadOnlyDictionary<string, string?>?, string?)

A message observed on or sent to a broker. Adapters map their technology's message onto this shape; the test-side API and the trace never see a broker-specific type.

public ProtoMessage(string Destination, string? Payload = null, IReadOnlyDictionary<string, string?>? Headers = null, string? ContentType = null)

Parameters

Destination string
Payload string
Headers IReadOnlyDictionary<string, string>
ContentType string

Properties

ContentType

public string? ContentType { get; init; }

Property Value

string

Destination

public string Destination { get; init; }

Property Value

string

Headers

public IReadOnlyDictionary<string, string?>? Headers { get; init; }

Property Value

IReadOnlyDictionary<string, string>

Payload

public string? Payload { get; init; }

Property Value

string

RoutingKey

The routing key the transport carried the message under, when it has one: the RabbitMQ adapter fills it from the delivery and publishes with it, and the in-memory broker keeps it on the message it stores. Null when the transport addresses by destination alone - the framework's RabbitMQ publish default is the destination itself, and a MassTransit destination is a message contract type with no routing key.

public string? RoutingKey { get; init; }

Property Value

string

Should

The assertions of this message, for example Should.MatchShape(shape).

[JsonIgnore]
public ProtoMessageAssertions Should { get; }

Property Value

ProtoMessageAssertions

Methods

MatchesShape(object, bool, JsonSerializerOptions?)

Whether the payload matches the expected shape exactly: a field the shape does not mention makes it false. Records nothing; see MatchesShape(object, JsonSerializerOptions?).

public bool MatchesShape(object expectedShape, bool exact, JsonSerializerOptions? options = null)

Parameters

expectedShape object
exact bool
options JsonSerializerOptions

Returns

bool

MatchesShape(object, JsonSerializerOptions?)

Whether the payload matches the expected shape, through the same matcher as Should.MatchShape: the fields the shape names must be there with those values, and others may be. Meant for choosing a message in an AwaitAsync predicate, so it records nothing and returns false for an empty, non-JSON or differently shaped payload. Assert the chosen message with Should.MatchShape.

public bool MatchesShape(object expectedShape, JsonSerializerOptions? options = null)

Parameters

expectedShape object
options JsonSerializerOptions

Returns

bool

ReadAsJson<T>(JsonSerializerOptions?)

Deserializes the payload as T, or returns default for an empty payload. Uses Reader (case-insensitive property names) unless options overrides it. A payload of the wrong shape throws JsonException; use ReadRequired<T>(JsonSerializerOptions?) when the payload must exist.

public T? ReadAsJson<T>(JsonSerializerOptions? options = null)

Parameters

options JsonSerializerOptions

Returns

T

Type Parameters

T

ReadRequired<T>(string, JsonSerializerOptions?)

Reads the value at jsonPath as T and fails when the payload is empty, the path does not resolve or the value is JSON null. The supported subset is $, dot members and [n] indices (see JsonPathResolver); a miss throws MessagingAssertionException naming the destination and the path.

public T ReadRequired<T>(string jsonPath, JsonSerializerOptions? options = null)

Parameters

jsonPath string
options JsonSerializerOptions

Returns

T

Type Parameters

T

ReadRequired<T>(JsonSerializerOptions?)

Deserializes the payload as T and fails when there is nothing to return: an empty payload or JSON null throws MessagingAssertionException naming the destination. The null check runs before the deserializer, so a value type reports the messaging assertion rather than a raw JsonException.

public T ReadRequired<T>(JsonSerializerOptions? options = null)

Parameters

options JsonSerializerOptions

Returns

T

Type Parameters

T