SseAssertions 0.4.0

Prefix Reserved
dotnet add package SseAssertions --version 0.4.0
                    
NuGet\Install-Package SseAssertions -Version 0.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SseAssertions" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SseAssertions" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="SseAssertions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SseAssertions --version 0.4.0
                    
#r "nuget: SseAssertions, 0.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SseAssertions@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SseAssertions&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=SseAssertions&version=0.4.0
                    
Install as a Cake Tool

SseAssertions

NuGet Downloads License: MIT .NET

Scope: Test projects only. Not intended for production code.

Framework-agnostic core for Server-Sent Events (SSE) assertions in .NET test projects. Defines the SseEvent public record (per the WHATWG / W3C SSE wire format), the SseFrameParser that turns wire text into IReadOnlyList<SseEvent>, the SseFailureMessage extension point for typed assertions, and the SseCountComparison enum that backs count terminators.

Full documentation, roadmap, and the TUnit adapter: github.com/JohnVerheij/SseAssertions.TUnit

What ships

Type Purpose
SseEvent (public record) Stable public data type. EventName (non-nullable, defaults to "message" per the WHATWG spec when no event: directive appears), Data (non-null), Id?, RetryMillis?.
SseFrameParser.Parse(string) WHATWG / W3C SSE wire-format parser; handles all three line terminators, strips a UTF-8 BOM at offset 0, ignores comment lines, accumulates multi-line data with \n joins.
SseFailureMessage Curated failure-message factories (ParseFailure, EventNotFound, EventCountMismatch, DataPredicateNotMatched, DataDeserializationFailed, RetryMillisPredicateNotMatched, UnexpectedContentType, CancellationCutRead, UncleanCancellation) for consumer-authored typed SSE assertions.
SseCountComparison (public enum) Comparison label (AtLeast, AtMost, Exactly) carried by EventCountMismatch.
SseFormat.LooksLikeServerSentEvents(string) Lightweight discriminator.

Test-framework-specific entry points live in adapter packages: SseAssertions.TUnit ships today. xUnit, NUnit, MSTest adapters are possible if demand surfaces.

Install

dotnet add package SseAssertions

Requirements: .NET 10. The package carries zero runtime dependencies beyond BCL.

License

MIT. Copyright (c) 2026 John Verheij.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SseAssertions:

Package Downloads
SseAssertions.TUnit

TUnit-native Server-Sent Events (SSE) assertions for .NET tests. HasSseEvent(eventName) chain on the string receiver with WithData / AtLeast / AtMost / Exactly terminators; flat HasSseEvent(eventName, minCount, ...) on Stream and HttpResponseMessage with cancellation-bounded partial-buffer reads and default-on Content-Type: text/event-stream validation. Builds on the SseAssertions framework-agnostic core. AOT-compatible, trimmable, no runtime reflection in the assertion path.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 45 6/4/2026
0.3.0 99 6/2/2026
0.2.0 160 5/21/2026
0.1.0 203 5/17/2026
0.0.1 179 5/17/2026

View the rendered release notes: https://github.com/JohnVerheij/SseAssertions.TUnit/releases/tag/v0.4.0

Minor release. Adds the `HttpResponseMessage` receiver to `EndsCleanlyOnCancellation`, so a cancellation-teardown assertion can run directly against an HTTP response without first extracting the body stream. The `0.3.0` retry-first surface already covered `string`, `Stream`, and `HttpResponseMessage`; this release closes the matching gap for the clean-cancellation assertion. Purely additive; the `0.3.0` ApiCompat baseline is preserved.

### Added

- **`Assert.That(response).EndsCleanlyOnCancellation(strictContentType, cancellationToken)`** on `HttpResponseMessage`. Reads the response body via `ReadAsStreamAsync(cancellationToken)` and asserts the read tears down via cooperative cancellation (the read completes, or raises `OperationCanceledException`) rather than surfacing a transport exception (`IOException`, `HttpRequestException`). Mirrors the existing `Stream` overload's teardown classification and the content-type handling of the other `HttpResponseMessage` receivers: `strictContentType` defaults to `true` (fails with the unexpected-content-type diagnostic when `Content-Type`'s media type is not `text/event-stream`); a null `Content` passes. Source-generated via `[GenerateAssertion]`.

### Changed

- Bumped `PackageValidationBaselineVersion` from `0.2.0` to `0.3.0` on both packages so ApiCompat strict-mode validates `0.4.0` against the most recently published baseline. The `0.4.0` change is purely additive; no `CompatibilitySuppressions.xml` updates required.
- README and packed-README clarification: `HasSseRetryDirectiveFirst` matches the WHATWG `retry:` directive field, not an `event: retry` named event. A stream that emits `event: retry` followed by a `data:` field carries no `retry:` field line, so the assertion correctly fails ("no retry directive was found"). The check is spec-strict and reads the wire-level field, not the dispatched event name.