dennisdoomen / dennisdoomen/fluentassertions.mockly
[API Proposal]: Add response-side assertions (WithResponseStatus, WithResponseBody, WithResponseBodyEquivalentTo)
- Dominant language
- C#
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Motivation
`WithResponseHeader` is the only assertion in the library that looks at the response. Everything else asserts on the request — even though `CapturedRequest.Response` is right there and holds the full `HttpResponseMessage`.
That means you cannot currently assert "this call returned a 201 with this body" through the Mockly assertions. You have to reach into `capturedRequest.Response` and assert on it by hand.
There is also a signal that this is wanted: the core repo carries a test-only `Mockly.Specs/HttpResponseMessageAssertions.cs` helper. The functionality exists, it just was never shipped to users.
## Proposed API
```csharp
requests.Should().ContainRequestFor("/api/users")
.WithResponseStatus(HttpStatusCode.Created)
.WithResponseBody("*created*")
.WithResponseBodyMatchingJson("{ \"id\": 1 }")
.WithResponseBodyEquivalentTo(new { id = 1, name = "John" });
```
These would sit on `ContainedRequestAssertions` next to the existing `WithResponseHeader`, and mirror the naming of the request-side `WithBody` / `WithBodyMatchingJson` / `WithBodyEquivalentTo` family so there is nothing new to learn.
## Notes
- Reading the response body is async; the existing assertions are all sync. Needs a decision on whether to block on the read or expose async assertions. Since the content is already buffered in memory for a mock, blocking is probably acceptable and keeps the fluent chain intact.
- Consider promoting the core repo's `HttpResponseMessageAssertions` test helper into this package rather than writing it twice.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with ContainedRequestAssertions, the existing WithResponseHeader assertion, and the request-side WithBody, WithBodyMatchingJson, and WithBodyEquivalentTo methods. Read Mockly.Specs/HttpResponseMessageAssertions.cs in the core repository and decide how response-body reads should fit the synchronous fluent API. Done means the proposed response status, body, JSON-matching, and equivalent-body assertions are available to users with coverage for their behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100