Skip to content

Add file/stream/bytes responders#129

Merged
dennisdoomen merged 1 commit into
mainfrom
dennisdoomen/file-stream-bytes-responders
May 30, 2026
Merged

Add file/stream/bytes responders#129
dennisdoomen merged 1 commit into
mainfrom
dennisdoomen/file-stream-bytes-responders

Conversation

@dennisdoomen

Copy link
Copy Markdown
Owner

Closes #123

Adds three additive, backward-compatible responders to RequestMockBuilder for large or binary payloads (file downloads, images, PDFs) without buffering everything into a string.

New API

  • RequestMockResponseBuilder RespondsWithFile(string path, string? contentType = null) — opens the file per request (fresh readable stream for each invocation) and infers the content type from the file extension via a small internal extension→MIME map, defaulting to application/octet-stream when not supplied. Sets Content-Type and Content-Length.
  • RequestMockResponseBuilder RespondsWithBytes(byte[] content, string contentType) — buffers the bytes so the mock can safely be invoked multiple times. Sets Content-Type.
  • RequestMockResponseBuilder RespondsWithStream(Stream stream, string contentType) — documents the single-read caveat (a Stream can only be consumed once); prefer RespondsWithBytes/RespondsWithFile for multi-invocation mocks. Sets Content-Type.

Tests

Added a RespondingWithBinaryPayloads spec class covering: file downloaded with correct bytes + inferred/explicit content-type, default content-type for unknown extensions, multi-invocation file mock, buffered byte content (single + multi-invocation), stream response, and the documented stream single-read behavior.

Notes

  • Public API surface changed → updated approved API verification files under Mockly.ApiVerificationTests/ApprovedApi via AcceptApiChanges.ps1.
  • Updated usage docs.
  • Full ./build.ps1 is green (compile, tests, API checks, inspect code) for both net472 and net8.0.

Do not merge — draft for maintainer review.

@dennisdoomen dennisdoomen added the enhancement New feature or request label May 30, 2026

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InspectCode found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@github-actions

github-actions Bot commented May 30, 2026

Copy link
Copy Markdown

Test Results

  3 files  ± 0    3 suites  ±0   35s ⏱️ +30s
133 tests + 8  133 ✅ + 8  0 💤 ±0  0 ❌ ±0 
263 runs  +16  263 ✅ +16  0 💤 ±0  0 ❌ ±0 

Results for commit d0b3c4f. ± Comparison against base commit bd7d742.

♻️ This comment has been updated with latest results.

@dennisdoomen dennisdoomen marked this pull request as ready for review May 30, 2026 13:46
@dennisdoomen dennisdoomen changed the title Add file/stream/bytes responders (closes #123) Add file/stream/bytes responders May 30, 2026
@dennisdoomen dennisdoomen force-pushed the dennisdoomen/file-stream-bytes-responders branch from 4b9b464 to fc69dce Compare May 30, 2026 15:26
@coveralls

coveralls commented May 30, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 26687775871

Coverage decreased (-1.7%) to 84.482%

Details

  • Coverage decreased (-1.7%) from the base build.
  • Patch coverage: 20 uncovered changes across 1 file (99 of 119 lines covered, 83.19%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
Mockly/RequestMockBuilder.cs 119 99 83.19%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1202
Covered Lines: 1087
Line Coverage: 90.43%
Relevant Branches: 409
Covered Branches: 274
Branch Coverage: 66.99%
Branches in Coverage %: Yes
Coverage Strength: 300.81 hits per line

💛 - Coveralls

Adds RespondsWithFile, RespondsWithStream and RespondsWithBytes to RequestMockBuilder for large/binary payloads. RespondsWithFile opens the file per request and infers content-type from the extension; RespondsWithBytes buffers bytes for multi-invocation; RespondsWithStream documents the single-read caveat.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dennisdoomen dennisdoomen force-pushed the dennisdoomen/file-stream-bytes-responders branch from fc69dce to d0b3c4f Compare May 30, 2026 15:34
@dennisdoomen dennisdoomen merged commit 5b7ddb4 into main May 30, 2026
10 checks passed
@dennisdoomen dennisdoomen deleted the dennisdoomen/file-stream-bytes-responders branch May 30, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add RespondsWithFile / RespondsWithStream / RespondsWithBytes for large/binary payloads

3 participants