Is your feature request related to a problem?
With Refit.Testing's StubHttp, every route needs an exact match on method, path, query, headers, etc. For tests that do not care about the exact request and just want a default response for anything not otherwise stubbed, that is more setup than the test needs. This was raised on PR #2195.
Describe the solution you'd like
A catch-all/fallback matcher on StubHttp's route table that responds to any request not matched by a more specific route, so a test can drop in one default reply instead of stubbing every route by hand. It should stay in Refit.Testing's flat, collection-initializer style rather than adding a fluent API, in line with the general goal of a mock framework that is perf/alloc-focused, easy to use, and test-framework agnostic.
Describe alternatives you've considered
A catch-all is already possible today with new RouteMatcher { Template = "*", Reusable = true }, but it's a workaround, not a real feature:
- It only works if it's the last entry in the table - reusable routes are matched in declaration order, so a "*" route earlier in the list shadows every reusable route after it.
- Nothing in the Route factory hints that this combination acts as a fallback.
Suggestions on how to achieve the feature
Add a Route.Fallback() factory (alongside Route.Get, Route.Post, etc.) that returns a RouteMatcher matching any method/path, and give StubHttp a third priority tier so fallback routes are always tried last - after one-shot and reusable routes - regardless of where they are declared in the table:
var http = new StubHttp
{
{ Route.Get("/users/{id}"), Reply.With(new User("octocat")) },
{ Route.Fallback(), Reply.Status(HttpStatusCode.OK) },
};
Is your feature request related to a problem?
With Refit.Testing's StubHttp, every route needs an exact match on method, path, query, headers, etc. For tests that do not care about the exact request and just want a default response for anything not otherwise stubbed, that is more setup than the test needs. This was raised on PR #2195.
Describe the solution you'd like
A catch-all/fallback matcher on StubHttp's route table that responds to any request not matched by a more specific route, so a test can drop in one default reply instead of stubbing every route by hand. It should stay in Refit.Testing's flat, collection-initializer style rather than adding a fluent API, in line with the general goal of a mock framework that is perf/alloc-focused, easy to use, and test-framework agnostic.
Describe alternatives you've considered
A catch-all is already possible today with
new RouteMatcher { Template = "*", Reusable = true }, but it's a workaround, not a real feature:Suggestions on how to achieve the feature
Add a
Route.Fallback()factory (alongsideRoute.Get,Route.Post, etc.) that returns a RouteMatcher matching any method/path, and give StubHttp a third priority tier so fallback routes are always tried last - after one-shot and reusable routes - regardless of where they are declared in the table: