Add HTTP method filtering to ContainRequestFor and NotContainRequestFor#53
Conversation
- 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"
| } | ||
|
|
||
| remainingPattern = urlPattern; | ||
| return null; |
There was a problem hiding this comment.
This should throw an exception of the prefix cannot be parsed as a valid HTTP method
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Why not call the overload that takes an HTTP method instead of reimplementing the code.
There was a problem hiding this comment.
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.
| mock.Requests.First().Should().BeUnexpected(); | ||
| ``` | ||
| --- | ||
| name: mockly |
There was a problem hiding this comment.
Bump the specs project to the latest version of Mockly and remove the imported skill again. This was fixed in 1.7.1
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Also add similar overloads to ContainRequestFor
There was a problem hiding this comment.
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.
…throw on invalid prefix, bump Mockly version, remove SKILL.md
|
@copilot Fix the build failures |
Head branch was pushed to by a user without write access
Fixed in commit
|
| string candidate = urlPattern[..spaceIndex]; | ||
| string candidateUpper = candidate.ToUpperInvariant(); | ||
|
|
||
| if (candidateUpper.All(c => c >= 'A' && c <= 'Z')) |
Coverage Report for CI Build 27839970615Coverage increased (+0.4%) to 87.954%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
|
@copilot can you create a PR for the main repo of Mockly to update the website pages on assertions? |
Both
ContainRequestForandNotContainRequestForonly 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
HttpMethodoverload forNotContainRequestFor— explicit method parameter as first argument:New
HttpMethodoverload forContainRequestFor— explicit method parameter as first argument:Method prefix syntax — case-insensitive HTTP method prefix in the URL string, supported on both methods:
URLs without a prefix continue to match all methods (backwards compatible). An
ArgumentExceptionis thrown when the prefix looks like an HTTP method (all alphabetic) but is not a recognised one.String overloads delegate to the
HttpMethodoverload when a method prefix is parsed, avoiding duplicated logic.API verification files updated for both v7 and v8 across
net472andnet8.0targets.New tests covering success and failure paths for both overloads and prefix syntax on both
ContainRequestForandNotContainRequestFor, including case-insensitivity of the prefix and the invalid-prefix exception.