Table of Contents

Class SseFormatAssertions

Namespace
SseAssertions.TUnit
Assembly
SseAssertions.TUnit.dll

TUnit-native fluent entry points for asserting on Server-Sent Events streams represented as text. v0.0.1 ships the IsServerSentEventsStream() discriminator only; the full surface (HTTP response bodies, streams, per-frame parsing, event-name / id / data assertions) ships in v0.1.0 once the wire-format parser is in place.

public static class SseFormatAssertions
Inheritance
SseFormatAssertions
Inherited Members

Remarks

Source methods carry the [GenerateAssertion] attribute; TUnit's source generator emits the fluent Assert.That(...).<Method>() entry point at consumer build time. The generated chain is AOT-clean (no runtime reflection in the assertion path).

Methods

HasFirstSseEvent(string, string)

Asserts the first SSE frame parsed from body has event: equal to eventName. Unlabelled frames match HasFirstSseEvent("message") per the WHATWG default-event-name rule.

[GenerateAssertion]
public static AssertionResult HasFirstSseEvent(this string body, string eventName)

Parameters

body string

The SSE wire-format body to inspect.

eventName string

The event-type name expected on the first frame.

Returns

AssertionResult

A passing assertion when the first parsed frame matches; otherwise a failing assertion naming the observed first event or reporting "no events".

Exceptions

ArgumentNullException

body or eventName is null.

HasSseRetryDirective(string, int?)

Asserts the SSE stream parsed from body contains a retry: directive. When millis is supplied, requires at least one frame whose retry: value equals it; when null, any non-null retry: value passes.

[GenerateAssertion]
public static AssertionResult HasSseRetryDirective(this string body, int? millis = null)

Parameters

body string

The SSE wire-format body to inspect.

millis int?

The required retry: value in milliseconds, or null to accept any value.

Returns

AssertionResult

A passing assertion when a matching retry: directive is found; otherwise a failing assertion describing what was observed.

Exceptions

ArgumentNullException

body is null.

HasSseRetryDirectiveFirst(string)

Asserts the SSE stream parsed from body sends a retry: directive before any data-bearing event. A retry: directive is a reconnection-time hint, not a named event, so this is distinct from HasFirstSseEvent: the contract is "the server set the reconnection time before streaming any payload". An empty data: line carries no payload and does not count as data: the standard ASP.NET Core SSE serializer emits a reconnection control frame as event: retry + an empty data: line + retry:, and that empty line must not be read as data preceding the directive.

[GenerateAssertion]
public static AssertionResult HasSseRetryDirectiveFirst(this string body)

Parameters

body string

The SSE wire-format body to inspect.

Returns

AssertionResult

A passing assertion when a retry: directive precedes the first data event; otherwise a failing assertion (no retry directive at all, or a data event came first).

Exceptions

ArgumentNullException

body is null.

HasSseRetryDirectiveFirst(string, int)

Asserts the SSE stream parsed from body sends a retry: directive before any data-bearing event and that the leading directive's value equals millis. The value-pinning companion to HasSseRetryDirectiveFirst(string): asserts both position and value in a single pass, where an empty data: control-frame line does not count as data (see HasSseRetryDirectiveFirst(string)).

[GenerateAssertion]
public static AssertionResult HasSseRetryDirectiveFirst(this string body, int millis)

Parameters

body string

The SSE wire-format body to inspect.

millis int

The required retry: value, in milliseconds, of the leading directive.

Returns

AssertionResult

A passing assertion when a retry: millis directive precedes the first data event; otherwise a failing assertion (no retry directive, a data event came first, or the leading directive carried a different value).

Exceptions

ArgumentNullException

body is null.

IsServerSentEventsStream(string)

Asserts that the supplied text has the shape of a Server-Sent Events stream: contains at least one SSE field marker (event:, data:, id:, or retry:) and the frame-separator double newline. The check is intentionally lightweight; structured per-frame assertions ship in v0.1.0.

[GenerateAssertion]
public static AssertionResult IsServerSentEventsStream(this string body)

Parameters

body string

The text to inspect, as the receiver of the fluent assertion.

Returns

AssertionResult

A passing assertion when the text looks like an SSE stream; otherwise a failing assertion identifying the shape mismatch.