Skip to content

feat!: add support for URL-encoded form data content#462

Merged
vbreuss merged 9 commits into
mainfrom
topic/add-support-for-formdata
Feb 7, 2026
Merged

feat!: add support for URL-encoded form data content#462
vbreuss merged 9 commits into
mainfrom
topic/add-support-for-formdata

Conversation

@vbreuss

@vbreuss vbreuss commented Feb 6, 2026

Copy link
Copy Markdown
Member

This pull request refactors and simplifies the HTTP content parameter matching APIs in the Mockolate.Web namespace. It removes specialized interfaces and classes for string and binary content, consolidates their functionality into a more general IHttpContentParameter interface, and introduces support for form data content. The changes improve API consistency and extensibility for matching HTTP request content in tests.

API Refactoring and Simplification:

  • Removed the specialized IsBinaryContent and IsStringContent extension methods, interfaces, and implementations, consolidating their functionality into the new, unified IHttpContentParameter interface. This includes removing IBinaryContentParameter, IStringContentParameter, and related code, and updating the API surface accordingly.

  • Updated the IHttpRequestMessageParameter interface and its implementation to remove WhoseStringContentIs and WhoseBinaryContentIs methods, replacing them with a more flexible WhoseContentIs method that optionally takes a media type and configuration action.

New Features:

  • Added support for matching HTTP form data parameters by introducing the HttpFormDataValue class and related API methods, such as WithFormData, to the IHttpContentParameter interface.

Other Improvements:

  • Improved string comparison in HttpQueryParameterValue.Matches to use StringComparison.Ordinal for consistency and correctness.
  • Minor code organization improvements, such as reordering fields in HttpRequestMessageParameter for clarity.

Test and Documentation Updates:

  • Updated the expected API surface in Mockolate_net10.0.txt to reflect the new interface structure and removed/added methods and classes.

These changes make the HTTP content matching API easier to use and extend, while reducing duplication and improving maintainability.

@vbreuss vbreuss self-assigned this Feb 6, 2026
Copilot AI review requested due to automatic review settings February 6, 2026 20:10
@vbreuss vbreuss added the enhancement New feature or request label Feb 6, 2026

Copilot 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.

Pull request overview

Adds a new It.IsFormDataContent() matcher to allow mocking/verifying HTTP calls based on URL-encoded form data (including form data embedded inside multipart form content).

Changes:

  • Introduces It.IsFormDataContent() and IFormDataContentParameter fluent API for matching form data content.
  • Adds parsing/matching logic for URL-encoded key/value pairs (including URL decoding).
  • Adds unit tests covering .Containing(...) matching behavior and order independence.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 12 comments.

File Description
Tests/Mockolate.Tests/Web/ItExtensionsTests.IsFormDataContentTests.cs Adds tests for the new form-data matcher behavior.
Source/Mockolate/Web/ItExtensions.cs Adds FormDataMatcher helper to extract and match URL-encoded form data.
Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Adds the public matcher API and hooks it into HttpContent matching.
Source/Mockolate/Web/HttpFormDataValue.cs Introduces a value wrapper for form-data matching with extensible match semantics.

Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Copilot AI review requested due to automatic review settings February 6, 2026 20:15
@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.3 LTS (Noble Numbat)
AMD EPYC 7763 3.20GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.102
[Host] : .NET 10.0.2 (10.0.2, 10.0.225.61305), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.627 μs 0.0219 μs 0.0194 μs 0.2270 - 3.73 KB
Simple_Moq 175.934 μs 0.8522 μs 0.7972 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.789 μs 0.0281 μs 0.0263 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.367 μs 0.0480 μs 0.0426 μs 0.4959 - 8.11 KB

Copilot 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.IsFormDataContent.cs Outdated
Comment thread Source/Mockolate/Web/HttpFormDataValue.cs
Comment thread Source/Mockolate/Web/HttpFormDataValue.cs
@vbreuss vbreuss force-pushed the topic/add-support-for-formdata branch from 59e83b1 to 4496dfa Compare February 6, 2026 20:17
…t.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 6, 2026 20:20

Copilot 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.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Comment thread Tests/Mockolate.Tests/Web/ItExtensionsTests.IsFormDataContentTests.cs Outdated
Comment thread Tests/Mockolate.Tests/Web/ItExtensionsTests.IsFormDataContentTests.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.cs Outdated
Comment thread Source/Mockolate/Web/HttpFormDataValue.cs
@github-actions

github-actions Bot commented Feb 6, 2026

Copy link
Copy Markdown

Test Results

    21 files  ±  0      21 suites  ±0   4m 52s ⏱️ -48s
 2 655 tests + 20   2 654 ✅ + 20  1 💤 ±0  0 ❌ ±0 
17 830 runs  +120  17 829 ✅ +120  1 💤 ±0  0 ❌ ±0 

Results for commit d089b0f. ± Comparison against base commit 2ae9bf8.

This pull request removes 108 and adds 128 tests. Note that renamed tests count towards both.
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2, 3, 4], expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2, 3], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 3], expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [1], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [2, 3], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [2], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1, 2, 3], expected: [3], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1], expected: [1], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsBinaryContentTests ‑ Containing_ShouldCheckForEquality(body: [1], expected: [2], expectSuccess: False)
…
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ ShouldSupportMonitoring
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ ShouldVerifyMediaType(mediaType: "image/gif", expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ ShouldVerifyMediaType(mediaType: "image/png", expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ ShouldVerifyMediaType(mediaType: "text/plain", expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ WithMediaType_ShouldVerifyMediaType(mediaType: "image/gif", expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ WithMediaType_ShouldVerifyMediaType(mediaType: "image/png", expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests ‑ WithMediaType_ShouldVerifyMediaType(mediaType: "text/plain", expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests+WithBytesContainingTests ‑ ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2, 3, 4], expectSuccess: False)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests+WithBytesContainingTests ‑ ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2, 3], expectSuccess: True)
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests+WithBytesContainingTests ‑ ShouldCheckForEquality(body: [1, 2, 3], expected: [1, 2], expectSuccess: True)
…

♻️ This comment has been updated with latest results.

Copilot AI review requested due to automatic review settings February 6, 2026 21:20

Copilot 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.

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 8 comments.

Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs Outdated
Comment thread Tests/Mockolate.Api.Tests/Expected/Mockolate_net8.0.txt
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Tests/Mockolate.Internal.Tests/WebTests.cs Outdated
@vbreuss vbreuss force-pushed the topic/add-support-for-formdata branch from 3140b1d to e9064e1 Compare February 6, 2026 21:28
@vbreuss vbreuss added the breaking change The changes require a new major version label Feb 6, 2026
@vbreuss vbreuss changed the title feat: add support for URL-encoded form data content feat!: add support for URL-encoded form data content Feb 6, 2026
Copilot AI review requested due to automatic review settings February 6, 2026 21:51

Copilot 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.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.

Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs Outdated
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate/Web/ItExtensions.HttpContent.cs
Comment thread Source/Mockolate/Web/HttpFormDataValue.cs Outdated
@sonarqubecloud

sonarqubecloud Bot commented Feb 7, 2026

Copy link
Copy Markdown

@vbreuss vbreuss merged commit 1787c7e into main Feb 7, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/add-support-for-formdata branch February 7, 2026 12:42
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown

This is addressed in release v1.3.0.

@github-actions github-actions Bot added the state: released The issue is released label Feb 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The changes require a new major version enhancement New feature or request state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants