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
-
Assertion<HttpResponseMessage>SseResponseEventIdsAssertion
- Implements
-
IAssertion
- Inherited Members
-
Assertion<HttpResponseMessage>.AssertAsync()Assertion<HttpResponseMessage>.GetAwaiter()Assertion<HttpResponseMessage>.AndAssertion<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
contextAssertionContext<HttpResponseMessage>The assertion context supplied by TUnit.
strictContentTypeboolWhen true, the assertion fails if the response
Content-Typemedia type is nottext/event-stream. Pass false for test mocks that serve SSE without the canonical header.cancellationTokenCancellationTokenThe 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
contextAssertionContext<HttpResponseMessage>The assertion context supplied by TUnit.
cancellationTokenCancellationTokenThe 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
metadataEvaluationMetadata<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
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
startingAtlongThe 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
eventNamestringThe event-type name that ends the window. Matched case-sensitively.
Returns
- SseResponseEventIdsAssertion
This assertion for chaining.
Exceptions
- ArgumentNullException
eventNameis null.