Class SseStreamEventIdsAssertion
- Namespace
- SseAssertions.TUnit
- Assembly
- SseAssertions.TUnit.dll
Fluent TUnit assertion that every Server-Sent Events frame read from a stream 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 Stream.
[AssertionExtension("HasSseEventIds")]
public sealed class SseStreamEventIdsAssertion : Assertion<Stream>, IAssertion
- Inheritance
-
Assertion<Stream>SseStreamEventIdsAssertion
- Implements
-
IAssertion
- Inherited Members
-
Assertion<Stream>.AssertAsync()Assertion<Stream>.GetAwaiter()Assertion<Stream>.AndAssertion<Stream>.Or
Remarks
The stream 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 stream or until the cancellation token ends it. On an
SseStream the next assertion continues after the last event this one read.
Constructors
SseStreamEventIdsAssertion(AssertionContext<Stream>, CancellationToken)
Initializes the assertion. Called by the TUnit source generator.
public SseStreamEventIdsAssertion(AssertionContext<Stream> context, CancellationToken cancellationToken = default)
Parameters
contextAssertionContext<Stream>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<Stream>)
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<Stream> metadata)
Parameters
metadataEvaluationMetadata<Stream>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 SseStreamEventIdsAssertion Sequential()
Returns
- SseStreamEventIdsAssertion
This assertion for chaining.
Sequential(long)
Requires the ids to be integers, each one more than the one before, starting at
startingAt.
public SseStreamEventIdsAssertion Sequential(long startingAt)
Parameters
startingAtlongThe id of the first event.
Returns
- SseStreamEventIdsAssertion
This assertion for chaining.
StrictlyIncreasing()
Requires the ids to be integers, each greater than the one before.
public SseStreamEventIdsAssertion StrictlyIncreasing()
Returns
- SseStreamEventIdsAssertion
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 SseStreamEventIdsAssertion Until(string eventName)
Parameters
eventNamestringThe event-type name that ends the window. Matched case-sensitively.
Returns
- SseStreamEventIdsAssertion
This assertion for chaining.
Exceptions
- ArgumentNullException
eventNameis null.