{"record":{"id":"862239fad36beeba","repo":"reactiveui/refit","slug":"no-request-has-been-received-yet","errorCode":null,"errorMessage":"No request has been received yet.","messagePattern":"No request has been received yet\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Refit.Testing/StubHttp.cs","lineNumber":222,"sourceCode":"        Justification = \"The interface type is intentionally specified explicitly by the caller, matching RestService.ForGenerated<T>.\")]\n    public T CreateGeneratedClient<T>(string hostUrl, RefitSettings baseSettings) => RestService.ForGenerated<T>(hostUrl, ToSettings(baseSettings));\n\n    /// <summary>Deserializes the body of the most recent request using the client's content serializer.</summary>\n    /// <typeparam name=\"T\">The type to deserialize the request body into.</typeparam>\n    /// <returns>The deserialized request body, or <see langword=\"default\"/> when the body is empty.</returns>\n    /// <exception cref=\"InvalidOperationException\">No request has been received yet.</exception>\n    [SuppressMessage(\n        \"Design\",\n        \"SST2307:Generic method type parameters should be inferable from the parameters\",\n        Justification = \"The body type is intentionally specified explicitly by the caller, like a deserialization target.\")]\n    public Task<T?> LastRequestBodyAsync<T>()\n    {\n        CapturedBody? body;\n        lock (_gate)\n        {\n            if (_bodies.Count == 0)\n            {\n                throw new InvalidOperationException(\"No request has been received yet.\");\n            }\n\n            body = _bodies[^1];\n        }\n\n        return DeserializeBodyAsync<T>(body);\n    }\n\n    /// <summary>Deserializes the body of the request at <paramref name=\"index\"/> using the client's content serializer.</summary>\n    /// <typeparam name=\"T\">The type to deserialize the request body into.</typeparam>\n    /// <param name=\"index\">The zero-based index into <see cref=\"Requests\"/>.</param>\n    /// <returns>The deserialized request body, or <see langword=\"default\"/> when the body is empty.</returns>\n    /// <exception cref=\"ArgumentOutOfRangeException\">No request exists at <paramref name=\"index\"/>.</exception>\n    [SuppressMessage(\n        \"Design\",\n        \"SST2307:Generic method type parameters should be inferable from the parameters\",\n        Justification = \"The body type is intentionally specified explicitly by the caller, like a deserialization target.\")]\n    public Task<T?> RequestBodyAsync<T>(int index)","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/reactiveui/refit/blob/b455f65ecc4c97d092317e349cb775f9cfc6bcdf/src/Refit.Testing/StubHttp.cs#L204-L240","documentation":"Thrown by StubHttp.LastRequestBodyAsync<T>() when you ask for the last received request body but the stub has captured zero requests. It is a test-helper guard ensuring you only inspect a body after a request has actually flowed through the stubbing HttpMessageHandler.","triggerScenarios":"Calling stub.LastRequestBodyAsync<T>() (or a sibling that reads _bodies) before any request has been sent through the stubbed client, or after only bodyless requests when no body was captured. The check is `_bodies.Count == 0` under a lock.","commonSituations":"Assertion ordering bug — calling the body assertion before invoking the client method; the SUT didn't actually issue the HTTP call (mocked out earlier); a GET request that has no body; forgetting to await the client call so the request never completed.","solutions":["Ensure the client call that produces the body has been made and awaited before asserting.","Guard the assertion: `if (stub.Requests.Count > 0) { var body = await stub.LastRequestBodyAsync<T>(); }`.","Verify with stub.Requests.Count that a request was received before inspecting bodies."],"exampleFix":"// before\nvar body = await stub.LastRequestBodyAsync<MyDto>(); // no request sent yet\n\n// after\nawait client.CreateAsync(dto);\nAssert.Equal(1, stub.Requests.Count);\nvar body = await stub.LastRequestBodyAsync<MyDto>();","handlingStrategy":"validation","validationCode":"// Check a request was captured before reading its body.\nif (stub.Requests.Count == 0)\n{\n    Assert.Fail(\"No request was sent through the stub.\");\n}\nvar body = await stub.LastRequestBodyAsync<MyDto>();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always drive the client call (and await it) before asserting on captured bodies.","Assert stub.Requests.Count equals the expected number first, then inspect bodies.","Remember GET requests typically have no body — use a body-bearing verb when you intend to assert a body."],"tags":["testing","stub","assertion","stub-http"],"backgroundTag":null,"analyzedSha":"b455f65ecc4c97d092317e349cb775f9cfc6bcdf","analyzedAt":"2026-08-13T21:20:57.878Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}