{"record":{"id":"d0614122ba82008f","repo":"reactiveui/refit","slug":"no-stubbed-route-matched-the-request-request-met","errorCode":null,"errorMessage":"No stubbed route matched the request: {request.Method} {request.RequestUri}","messagePattern":"No stubbed route matched the request: (.+?) (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Refit.Testing/StubHttp.cs","lineNumber":347,"sourceCode":"        // for typed inspection even after the client disposes the request.\n        await BufferRequestAsync(request, requestIndex).ConfigureAwait(false);\n\n        // Priority tiers, tried in order regardless of declaration order: one-shot expectations, then reusable\n        // background stubs, then catch-all fallbacks.\n        var index = await FindMatchAsync(request, RouteTier.OneShot, cancellationToken).ConfigureAwait(false);\n        if (index < 0)\n        {\n            index = await FindMatchAsync(request, RouteTier.Reusable, cancellationToken).ConfigureAwait(false);\n        }\n\n        if (index < 0)\n        {\n            index = await FindMatchAsync(request, RouteTier.Fallback, cancellationToken).ConfigureAwait(false);\n        }\n\n        if (index < 0)\n        {\n            throw new InvalidOperationException(\n                $\"No stubbed route matched the request: {request.Method} {request.RequestUri}\");\n        }\n\n        if (!_routes[index].Reusable && !_routes[index].Fallback)\n        {\n            Consume(index);\n        }\n\n        var faulted = await ApplyBehaviorAsync(request, cancellationToken).ConfigureAwait(false);\n        if (faulted is not null)\n        {\n            return faulted;\n        }\n\n        var response = await BuildResponseAsync(_responses[index], request).ConfigureAwait(false);\n\n        // Honor cancellation requested during matching or by a responder (e.g. a test that cancels mid-send).\n        cancellationToken.ThrowIfCancellationRequested();","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Testing/StubHttp.cs#L329-L365","documentation":"Thrown by StubHttp during SendAsync when an outgoing request matches none of the registered stubbed routes (checked across one-shot, reusable, and fallback tiers). The stub is a strict matcher — every request must be expected — so an unregistered request is treated as a test failure rather than a live call.","triggerScenarios":"The code under test issues a request (method or URI) that was not set up with stub.Expect(...)/Route(...), or whose URL differs (query string, trailing slash, casing in path, base address). FindMatchAsync returns -1 for all tiers and the guard fires.","commonSituations":"Mismatched HTTP method (expected POST, got PUT); URL template/path differences; query parameters not accounted for; forgot to register a route for a secondary call the SUT makes (e.g. token refresh, retries); base address/relative path mismatch changing the RequestUri.","solutions":["Register a matching route: stub.Expect(HttpMethod.Post, \"api/items\") (use a fallback or reusable route if the exact URI varies).","Compare the actual request in the error message to the registered templates and align method/path.","If the call is incidental to the test, register a reusable/fallback route to absorb it rather than letting it fail matching."],"exampleFix":"// before — request made but no route registered\nawait client.PostAsync(payload);\n\n// after\nstub.Expect(HttpMethod.Post, \"api/items\").WithBody(payload).Respond(200);\nawait client.PostAsync(payload);","handlingStrategy":"validation","validationCode":"// Register a fallback so unexpected calls surface clearly instead of mismatching,\n// or assert the call will match a registered route beforehand.\nif (stub.Requests.Count == 0)\n{\n    Assert.Fail(\"No request was sent through the stub.\");\n}\n// Optionally: stub.ExpectAny() / a fallback route to absorb incidental calls.","typeGuard":null,"tryCatchPattern":"// Inspect the failure message for the actual method/URI, then register the matching route.\n// The exception already prints: No stubbed route matched the request: POST http://.../api/x\nstub.Expect(HttpMethod.Post, \"api/x\").Respond(200);","preventionTips":["Register routes for every call the SUT makes, including secondary ones (auth, retries).","Use a fallback route to catch and diagnose stray requests during test authoring.","Align HTTP method, path, and query exactly between expectation and actual request."],"tags":["testing","stub","route-matching","stub-http"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}