Skip to content

Add HTTP method filtering to ContainRequestFor and NotContainRequestFor#53

Merged
dennisdoomen merged 5 commits into
mainfrom
copilot/add-filtering-by-http-method
Jun 20, 2026
Merged

Add HTTP method filtering to ContainRequestFor and NotContainRequestFor#53
dennisdoomen merged 5 commits into
mainfrom
copilot/add-filtering-by-http-method

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Both ContainRequestFor and NotContainRequestFor only matched by URL pattern, making it impossible to write narrow assertions when multiple HTTP methods target the same path (e.g. assert no PUT occurred while a GET to the same URL is legitimate, or assert that only a POST — not a GET — was captured).

Changes

  • New HttpMethod overload for NotContainRequestFor — explicit method parameter as first argument:

    mock.Requests.Should().NotContainRequestFor(HttpMethod.Put, "/config/slotConfigNames");
  • New HttpMethod overload for ContainRequestFor — explicit method parameter as first argument:

    mock.Requests.Should().ContainRequestFor(HttpMethod.Post, "/api/resource");
  • Method prefix syntax — case-insensitive HTTP method prefix in the URL string, supported on both methods:

    mock.Requests.Should().NotContainRequestFor("PUT /config/slotConfigNames");
    mock.Requests.Should().NotContainRequestFor("delete /api/members/42");
    mock.Requests.Should().ContainRequestFor("POST /api/resource");

    URLs without a prefix continue to match all methods (backwards compatible). An ArgumentException is thrown when the prefix looks like an HTTP method (all alphabetic) but is not a recognised one.

  • String overloads delegate to the HttpMethod overload when a method prefix is parsed, avoiding duplicated logic.

  • API verification files updated for both v7 and v8 across net472 and net8.0 targets.

  • New tests covering success and failure paths for both overloads and prefix syntax on both ContainRequestFor and NotContainRequestFor, including case-insensitivity of the prefix and the invalid-prefix exception.

- Add NotContainRequestFor(HttpMethod, string, ...) overload
- Add HTTP method prefix parsing in NotContainRequestFor(string, ...)
  e.g. NotContainRequestFor(\"PUT /api/resource\")
- Add 5 new tests covering both features
- Update 4 API verification files

Closes #52"
Copilot AI changed the title [WIP] Add support for filtering NotContainRequestFor by HTTP method Add HTTP method filtering to NotContainRequestFor Jun 19, 2026
Copilot AI requested a review from dennisdoomen June 19, 2026 07:04
}

remainingPattern = urlPattern;
return null;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This should throw an exception of the prefix cannot be parsed as a valid HTTP method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. TryParseMethodPrefix now throws an ArgumentException when the token before the first space is all-alphabetic but not in the known HTTP methods set, e.g. "CUSTOM /api/foo""'CUSTOM' is not a recognized HTTP method. Use one of: CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT, TRACE.". A test covering this case was added for both ContainRequestFor and NotContainRequestFor.

params object[] becauseArgs)
{
var matches = subject.Where(r => r.Uri is not null && r.Uri.ToString().MatchesWildcard(urlPattern)).ToList();
HttpMethod? parsedMethod = TryParseMethodPrefix(urlPattern, out string parsedUrlPattern);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why not call the overload that takes an HTTP method instead of reimplementing the code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Refactored. The string overload now delegates to NotContainRequestFor(HttpMethod, string) when a method prefix is successfully parsed, and only keeps its own "all methods" matching path for the no-prefix case.

Comment thread .agents/skills/mockly/SKILL.md Outdated
mock.Requests.First().Should().BeUnexpected();
```
---
name: mockly

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Bump the specs project to the latest version of Mockly and remove the imported skill again. This was fixed in 1.7.1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Both Specs projects now reference Mockly at [1.7.1,2.0.0) and the .agents/skills/mockly/SKILL.md file has been removed.

/// <param name="becauseArgs">
/// Zero or more objects to format using the placeholders in <paramref name="because" />.
/// </param>
public AndConstraint<RequestCollectionAssertions> NotContainRequestFor(HttpMethod method, string urlPattern,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also add similar overloads to ContainRequestFor

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added. ContainRequestFor now has the same two additions: an HttpMethod overload (ContainRequestFor(HttpMethod method, string urlPattern, ...)) and method-prefix syntax support in the string overload (ContainRequestFor("POST /api/resource")). The string overload delegates to the HttpMethod overload when a prefix is parsed. API verification files updated and 5 new tests added.

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Test Results

  5 files  ± 0    5 suites  ±0   8s ⏱️ -2s
127 tests +11  127 ✅ +11  0 💤 ±0  0 ❌ ±0 
496 runs  +44  496 ✅ +44  0 💤 ±0  0 ❌ ±0 

Results for commit 24fe476. ± Comparison against base commit e521b4a.

♻️ This comment has been updated with latest results.

Copilot AI changed the title Add HTTP method filtering to NotContainRequestFor Add HTTP method filtering to ContainRequestFor and NotContainRequestFor Jun 19, 2026
Copilot AI requested a review from dennisdoomen June 19, 2026 11:39
@dennisdoomen dennisdoomen added the enhancement New feature or request label Jun 19, 2026
@dennisdoomen dennisdoomen marked this pull request as ready for review June 19, 2026 13:16
@dennisdoomen dennisdoomen enabled auto-merge (squash) June 19, 2026 13:16
@dennisdoomen

Copy link
Copy Markdown
Owner

@copilot Fix the build failures

auto-merge was automatically disabled June 19, 2026 17:31

Head branch was pushed to by a user without write access

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the build failures

Fixed in commit 84f837b (and now Fix API verification: correct method ordering in verified files, remove SKILL.md). The CI failures were caused by two issues:

  1. API verification files had incorrect method ordering — the ContainRequestFor(HttpMethod, ...) and NotContainRequestFor(HttpMethod, ...) overloads were placed before the Uri and string overloads in the verified files, but the actual code generates them after. Updated all four verified files to match the received output.

  2. SKILL.md was accidentally committed — the .agents/skills/mockly/SKILL.md was being added by the Mockly 1.7.0 package build targets and got committed despite the .gitignore. Removed it with git rm so the .gitignore takes effect again.

string candidate = urlPattern[..spaceIndex];
string candidateUpper = candidate.ToUpperInvariant();

if (candidateUpper.All(c => c >= 'A' && c <= 'Z'))
@coveralls

coveralls commented Jun 19, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 27839970615

Coverage increased (+0.4%) to 87.954%

Details

  • Coverage increased (+0.4%) from the base build.
  • Patch coverage: 6 uncovered changes across 1 file (87 of 93 lines covered, 93.55%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
Shared/HttpMockAssertionExtensions.cs 93 87 93.55%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 930
Covered Lines: 837
Line Coverage: 90.0%
Relevant Branches: 556
Covered Branches: 470
Branch Coverage: 84.53%
Branches in Coverage %: Yes
Coverage Strength: 23.2 hits per line

💛 - Coveralls

@dennisdoomen dennisdoomen merged commit 2143354 into main Jun 20, 2026
6 checks passed
@dennisdoomen dennisdoomen deleted the copilot/add-filtering-by-http-method branch June 20, 2026 11:10
@dennisdoomen

Copy link
Copy Markdown
Owner

@copilot can you create a PR for the main repo of Mockly to update the website pages on assertions?

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.

4 participants