Skip to content

Commit fb791b5

Browse files
baywetCopilot
andcommitted
Make HTTP lifecycle test response disposal explicit
Scope separate responses for the two factory-client requests while preserving the existing client-disposal assertions. Co-authored-by: Copilot <[email protected]> Copilot-Session: 1cdccb3e-5134-4b05-9065-b0a181c4b46d
1 parent 050475d commit fb791b5

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/DefaultHttpRequestHandlerTests.cs‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ public void ConstructorWithNullHttpClientFactoryThrows()
4040
public async Task SendAsyncUsesNamedFactoryAndDisposesClientsAsync()
4141
{
4242
// Arrange
43-
using TestHttpMessageHandler messageHandler = new((req, _) =>
44-
Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)
45-
{
46-
Content = new StringContent("ok", Encoding.UTF8, "text/plain"),
47-
}));
43+
using HttpResponseMessage firstResponse = new(HttpStatusCode.OK)
44+
{
45+
Content = new StringContent("ok", Encoding.UTF8, "text/plain"),
46+
};
47+
using HttpResponseMessage secondResponse = new(HttpStatusCode.OK)
48+
{
49+
Content = new StringContent("ok", Encoding.UTF8, "text/plain"),
50+
};
51+
int requestCount = 0;
52+
#pragma warning disable CA2025
53+
using TestHttpMessageHandler messageHandler = new((_, _) =>
54+
Task.FromResult(requestCount++ == 0 ? firstResponse : secondResponse));
55+
#pragma warning restore CA2025
4856
using HttpClient firstClient = new(messageHandler, disposeHandler: false);
4957
using HttpClient secondClient = new(messageHandler, disposeHandler: false);
5058
Mock<IHttpClientFactory> factory = new();

0 commit comments

Comments
 (0)