Skip to content

Add WithBodyHavingPropertiesEqualTo and change WithBodyHavingPropertiesOf to partial matching#74

Merged
dennisdoomen merged 2 commits intomainfrom
copilot/rename-withbodyhavingpropertiesof
Feb 19, 2026
Merged

Add WithBodyHavingPropertiesEqualTo and change WithBodyHavingPropertiesOf to partial matching#74
dennisdoomen merged 2 commits intomainfrom
copilot/rename-withbodyhavingpropertiesof

Conversation

Copy link
Contributor

Copilot AI commented Feb 19, 2026

WithBodyHavingPropertiesOf was doing an exact dictionary match, making it fail whenever the request body contained properties beyond what was specified. The name implies partial/subset matching, which was misleading.

Changes

  • WithBodyHavingPropertiesOf — now filters the actual body to only the keys in the expected dictionary before comparing, making it a true subset/partial match that ignores extra properties
  • WithBodyHavingPropertiesEqualTo (new) — preserves the original exact-match behavior, requiring the body and expected dictionary to be fully equivalent with no extra properties
  • API verification files — updated all four .verified.txt files to include WithBodyHavingPropertiesEqualTo
  • Tests — added Ignores_extra_properties_in_body for WithBodyHavingPropertiesOf and a new WithBodyHavingPropertiesEqualTo test class covering match, extra-properties failure, and value-mismatch failure

Example

// Passes even if the captured request body has additional properties beyond those specified
mock.Requests.Should().ContainRequest().WithBodyHavingPropertiesOf(new Dictionary<string, string>
{
    { "fnv_activity", "someid" },
    { "statuscode", "someid" },
});

// Requires the body to match exactly — fails if body has any extra properties
mock.Requests.Should().ContainRequest().WithBodyHavingPropertiesEqualTo(new Dictionary<string, string>
{
    { "fnv_activity", "someid" },
    { "statuscode", "someid" },
});
Original prompt

This section details on the original issue you should resolve

<issue_title>Rename WithBodyHavingPropertiesOf to WithBodyHavingPropertiesEqualTo.</issue_title>
<issue_description>The method name WithBodyHavingPropertiesOf suggest it should check if a request at least contains those properties:

httpMock.Requests.Should().ContainRequest().WithBodyHavingPropertiesOf(new Dictionary<string, string>
        {
            { "fnv_activity", "someid" },
            { "fnv_account@odata.bind", $"/accounts({companyId})" },
            { "fnv_portalstatus", "someid" },
            { "statuscode", "someid" },
            { "fnv_enddateincomerelationship", "2021-12-31" },
            { "fnv_startdateincomerelationship", "2022-01-01" },
        });

But when the captured request contains more properties it'll throw:
Expected the top-level properties of the request body to be equivalent to the provided dictionary, but it failed with:.

Therefore I would like to suggest renaming the existing method to WithBodyHavingPropertiesEqualTo. And perhaps reimplementing WithBodyHavingPropertiesOf with the expected behavior.

</issue_description>

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

@dennisdoomen We need to ensure backwards compatibility and implement it as such:
  • Modify WithBodyHavingPropertiesOf to only look at the properties of the provided dictionary. If the request body contains other properties, they should be ignored.
  • Add WithBodyHavingPropertiesEqualTo that requires the body to only have the properties of the provided dictionary and match the values. </comment_new>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…esOf for partial matching

Co-authored-by: dennisdoomen <572734+dennisdoomen@users.noreply.github.com>
Copilot AI changed the title [WIP] Rename WithBodyHavingPropertiesOf to WithBodyHavingPropertiesEqualTo Add WithBodyHavingPropertiesEqualTo and change WithBodyHavingPropertiesOf to partial matching Feb 19, 2026
Copilot AI requested a review from dennisdoomen February 19, 2026 19:06
@dennisdoomen dennisdoomen added the enhancement New feature or request label Feb 19, 2026
@dennisdoomen dennisdoomen marked this pull request as ready for review February 19, 2026 19:12
/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndWhichConstraint<ContainedRequestAssertions, CapturedRequest> WithBodyHavingPropertiesEqualTo(

Check notice

Code scanning / InspectCode

Type member is never used: Non-private accessibility Note

Method 'WithBodyHavingPropertiesEqualTo' is never used
@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Test Results

  3 files  ±0    3 suites  ±0   7s ⏱️ +3s
125 tests +4  125 ✅ +4  0 💤 ±0  0 ❌ ±0 
244 runs  +8  244 ✅ +8  0 💤 ±0  0 ❌ ±0 

Results for commit 2a93ad2. ± Comparison against base commit 63d9dd0.

♻️ This comment has been updated with latest results.

@coveralls
Copy link

coveralls commented Feb 19, 2026

Pull Request Test Coverage Report for Build 22196013946

Details

  • 30 of 42 (71.43%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.3%) to 82.336%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Shared/HttpMockAssertionExtensions.cs 30 42 71.43%
Totals Coverage Status
Change from base Build 22051748791: -0.3%
Covered Lines: 1171
Relevant Lines: 1354

💛 - Coveralls

@dennisdoomen dennisdoomen merged commit ddb2380 into main Feb 19, 2026
10 checks passed
@dennisdoomen dennisdoomen deleted the copilot/rename-withbodyhavingpropertiesof branch February 19, 2026 19:21
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.

Rename WithBodyHavingPropertiesOf to WithBodyHavingPropertiesEqualTo.

3 participants