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
bodystringThe SSE wire-format body to inspect.
eventNamestringThe 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
bodyoreventNameis 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
bodystringThe SSE wire-format body to inspect.
millisint?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
bodyis 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
bodystringThe 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
bodyis 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
bodystringThe SSE wire-format body to inspect.
millisintThe required
retry:value, in milliseconds, of the leading directive.
Returns
- AssertionResult
A passing assertion when a
retry: millisdirective 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
bodyis 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
bodystringThe 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.