Table of Contents

Class SseResponseEventIdsAssertion

Namespace
SseAssertions.TUnit
Assembly
SseAssertions.TUnit.dll

Fluent TUnit assertion that every Server-Sent Events frame in a response body carries an id:, and, with StrictlyIncreasing() or Sequential(), that the ids are integers in that order (the property a Last-Event-ID reconnection relies on). Until(eventName) ends the window at a named event. The failure lists the ids seen. Constructed by the TUnit source generator from the HasSseEventIds extension on HttpResponseMessage.

[AssertionExtension("HasSseEventIds")]
public sealed class SseResponseEventIdsAssertion : Assertion<HttpResponseMessage>, IAssertion
Inheritance
SseResponseEventIdsAssertion
Implements
IAssertion
Inherited Members
Assertion<HttpResponseMessage>.AssertAsync()
Assertion<HttpResponseMessage>.GetAwaiter()
Assertion<HttpResponseMessage>.And
Assertion<HttpResponseMessage>.Or

Remarks

The body is read event by event and the read stops at the first violation or at the Until event; otherwise it runs to the end of the body or until the cancellation token ends it. Unless strictContentType is false, a response that is not text/event-stream fails before the body is read.

Constructors

SseResponseEventIdsAssertion(AssertionContext<HttpResponseMessage>, bool, CancellationToken)

Initializes the assertion. Called by the TUnit source generator.

public SseResponseEventIdsAssertion(AssertionContext<HttpResponseMessage> context, bool strictContentType, CancellationToken cancellationToken = default)

Parameters

context AssertionContext<HttpResponseMessage>

The assertion context supplied by TUnit.

strictContentType bool

When true, the assertion fails if the response Content-Type media type is not text/event-stream. Pass false for test mocks that serve SSE without the canonical header.

cancellationToken CancellationToken

The upper bound of the read; its cancellation ends the read and the events that arrived are evaluated.

SseResponseEventIdsAssertion(AssertionContext<HttpResponseMessage>, CancellationToken)

Initializes the assertion with the Content-Type check on. Called by the TUnit source generator.

public SseResponseEventIdsAssertion(AssertionContext<HttpResponseMessage> context, CancellationToken cancellationToken = default)

Parameters

context AssertionContext<HttpResponseMessage>

The assertion context supplied by TUnit.

cancellationToken CancellationToken

The upper bound of the read; its cancellation ends the read and the events that arrived are evaluated.

Methods

CheckAsync(EvaluationMetadata<HttpResponseMessage>)

Implements the specific check logic for this assertion. Called after the context has been evaluated. Override this method if your assertion uses the default AssertAsync() flow. If you override AssertAsync() with custom logic (like AndAssertion/OrAssertion), you don't need to implement this.

protected override Task<AssertionResult> CheckAsync(EvaluationMetadata<HttpResponseMessage> metadata)

Parameters

metadata EvaluationMetadata<HttpResponseMessage>

Metadata about the evaluation including value, exception, and timing information

Returns

Task<AssertionResult>

The result of the assertion check

GetExpectation()

Gets a human-readable description of what this assertion expects. Used in error messages.

protected override string GetExpectation()

Returns

string

Sequential()

Requires the ids to be integers, each one more than the one before, from any first id.

public SseResponseEventIdsAssertion Sequential()

Returns

SseResponseEventIdsAssertion

This assertion for chaining.

Sequential(long)

Requires the ids to be integers, each one more than the one before, starting at startingAt.

public SseResponseEventIdsAssertion Sequential(long startingAt)

Parameters

startingAt long

The id of the first event.

Returns

SseResponseEventIdsAssertion

This assertion for chaining.

StrictlyIncreasing()

Requires the ids to be integers, each greater than the one before.

public SseResponseEventIdsAssertion StrictlyIncreasing()

Returns

SseResponseEventIdsAssertion

This assertion for chaining.

Until(string)

Ends the observation window after the first event of type eventName: only the events up to and including it are checked, and the read stops there. When the token ends the read before that event arrives, the assertion fails naming it; when the stream ends first, the whole stream is the window.

public SseResponseEventIdsAssertion Until(string eventName)

Parameters

eventName string

The event-type name that ends the window. Matched case-sensitively.

Returns

SseResponseEventIdsAssertion

This assertion for chaining.

Exceptions

ArgumentNullException

eventName is null.