Skip to content

Add WithBody(object) overload to RequestMockBuilder for JSON body matching#80

Merged
dennisdoomen merged 3 commits intomainfrom
copilot/add-withbody-to-requestmockbuilder
Mar 10, 2026
Merged

Add WithBody(object) overload to RequestMockBuilder for JSON body matching#80
dennisdoomen merged 3 commits intomainfrom
copilot/add-withbody-to-requestmockbuilder

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

  • Add WithBody(object body) overload to RequestMockBuilder that serializes the object to JSON and matches using JSON equivalence
  • Add tests to HttpMockSpecs.cs for the new method (success case + error message case)
  • Update API verification files for net8.0 and net472 (via AcceptApiChanges)
  • Update legacy API verification files for net47, netstandard2.0, netstandard2.1 for consistency
  • Remove the "invalid JSON" sentence from WithBody(object) XML remarks
  • Add WithBody(object) usage example to website/docs/advanced.md
Original prompt

This section details on the original issue you should resolve

<issue_title>Add WithBody to the RequestMockBuilder that takes an object that will be serialized to JSON</issue_title>
<issue_description>This should enable scenarios like

httpMock
            .ForPatch().WithPath($"IncomeRelationships/{contact.PrimaryIncomeRelationship.Id}")
            .WithBody(new
            {
                EntityKey = "TheRuleKey",
                RepresentativeId = representativeToAssign.ToString()
            })
            .RespondsWithStatus(HttpStatusCode.NoContent);
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ed object matching

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Copilot AI changed the title [WIP] Add WithBody method to RequestMockBuilder for JSON serialization Add WithBody(object) overload to RequestMockBuilder for JSON body matching Mar 9, 2026
Comment thread Mockly/RequestMockBuilder.cs
Comment thread Mockly/RequestMockBuilder.cs Outdated
…anced.md example

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
@dennisdoomen dennisdoomen marked this pull request as ready for review March 10, 2026 18:22
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 10, 2026

Test Results

  3 files  ±0    3 suites  ±0   6s ⏱️ -1s
129 tests +2  129 ✅ +2  0 💤 ±0  0 ❌ ±0 
252 runs  +4  252 ✅ +4  0 💤 ±0  0 ❌ ±0 

Results for commit e660a11. ± Comparison against base commit 4f5b817.

♻️ This comment has been updated with latest results.

@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22917510352

Details

  • 5 of 7 (71.43%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.09%) to 83.371%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Mockly/RequestMockBuilder.cs 5 7 71.43%
Totals Coverage Status
Change from base Build 22618149662: -0.09%
Covered Lines: 1198
Relevant Lines: 1371

💛 - Coveralls

@dennisdoomen dennisdoomen added the enhancement New feature or request label Mar 10, 2026
@dennisdoomen dennisdoomen merged commit 45b198f into main Mar 10, 2026
10 checks passed
@dennisdoomen dennisdoomen deleted the copilot/add-withbody-to-requestmockbuilder branch March 10, 2026 18:30
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 WithBody to the RequestMockBuilder that takes an object that will be serialized to JSON

3 participants