{"record":{"id":"92349acf8b7a8324","repo":"reactiveui/refit","slug":"missing-count-expected-request-s-were-not-made","errorCode":null,"errorMessage":"{missing.Count} expected request(s) were not made:{Environment.NewLine}{string.Join(Environment.NewLine, missing)}","messagePattern":"(.+?) expected request\\(s\\) were not made:(.+?)(.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Refit.Testing/StubHttp.cs","lineNumber":536,"sourceCode":"        {\n            for (var i = 0; i < _routes.Count; i++)\n            {\n                var route = _routes[i];\n                if (route.Reusable || route.Fallback || _consumed[i])\n                {\n                    continue;\n                }\n\n                missing.Add($\"  - {route.Method?.Method ?? \"ANY\"} {route.Template}\");\n            }\n        }\n\n        if (missing.Count == 0)\n        {\n            return;\n        }\n\n        throw new InvalidOperationException(\n            $\"{missing.Count} expected request(s) were not made:{Environment.NewLine}{string.Join(Environment.NewLine, missing)}\");\n    }\n\n    /// <summary>Marks a non-reusable route consumed and signals completion once the last one is hit.</summary>\n    /// <param name=\"index\">The index of the route that satisfied a request.</param>\n    /// <remarks>\n    /// Excluded from coverage: the double-consume guard only triggers when two requests race the same\n    /// one-shot route between matching and consumption, which cannot be exercised deterministically.\n    /// </remarks>\n    [ExcludeFromCodeCoverage]\n    private void Consume(int index)\n    {\n        lock (_gate)\n        {\n            if (_consumed[index])\n            {\n                return;\n            }","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Testing/StubHttp.cs#L518-L554","documentation":"Thrown by StubHttp.ThrowIfOutstanding (invoked at validation/disposal) when one or more non-reusable, non-fallback routes were registered as expected but never hit by a request. It enforces that every one-shot expectation you set up actually occurred, surfacing a list of the unmet routes.","triggerScenarios":"You registered an expectation (a one-shot route) but the system under test never made that request (or made it to a different URI/method). At verification time the stub iterates routes and collects any non-reusable/non-fallback route whose _consumed flag is still false, then throws with the list.","commonSituations":"Over-specifying expectations (asserting a call path the SUT didn't take); the SUT short-circuited via caching/validation; an exception earlier in the test prevented the call; the route URI didn't quite match so a fallback absorbed it instead.","solutions":["Make the SUT perform the expected call, or remove expectations for calls you don't actually require.","If the call is optional, register it as reusable (so it never counts against outstanding expectations).","Inspect the listed missing routes and reconcile with the actual requests captured in stub.Requests to find the URI/method mismatch."],"exampleFix":"// before — expected but never called\nstub.Expect(HttpMethod.Delete, \"api/items/5\").Respond(204);\nawait client.GetAsync(5); // forgot to delete\nstub.Verify(); // throws: 1 expected request(s) not made\n\n// after — perform the expected call, or mark reusable\nawait client.DeleteAsync(5);\nstub.Verify();","handlingStrategy":"validation","validationCode":"// Prefer asserting the calls you actually expect; reuse routes for optional calls.\n// Before verifying, cross-check registered one-shot routes against stub.Requests.\nforeach (var r in stub.RegisteredRoutes)\n{\n    // ensure your SUT performs each expected call, or remove the expectation\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only register one-shot expectations for calls the SUT must make; mark optional ones reusable.","Call stub.Verify()/dispose in the test to surface unmet expectations immediately, near the cause.","Compare the missing-routes list against stub.Requests to find URI/method mismatches."],"tags":["testing","stub","verification","stub-http"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}