| 1 | using AgentForge.Abstractions; |
| 2 | using AgentForge.Services; |
| 3 | using Microsoft.AspNetCore.Http; |
| 4 | using Microsoft.AspNetCore.Mvc.Testing; |
| 5 | |
| 6 | namespace AgentForge.Tests; |
| 7 | |
| 8 | /// <summary>In-process MCP invoke for integration tests (no HTTP loopback).</summary> |
| 9 | public sealed class TestForgeMcpHttpClientSource(ForgeWebApplicationFactory factory) : IForgeMcpHttpClientSource |
| 10 | { |
| 11 | public HttpClient CreateClient(HttpContext context) |
| 12 | { |
| 13 | var client = factory.CreateClient(new WebApplicationFactoryClientOptions |
| 14 | { |
| 15 | AllowAutoRedirect = false, |
| 16 | }); |
| 17 | |
| 18 | if (context.Request.Headers.Authorization is { Count: > 0 } authorization) |
| 19 | client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", authorization.ToString()); |
| 20 | |
| 21 | if (context.Request.Headers.TryGetValue("X-Forge-Actor", out var actor) && !string.IsNullOrWhiteSpace(actor)) |
| 22 | client.DefaultRequestHeaders.TryAddWithoutValidation("X-Forge-Actor", actor.ToString()); |
| 23 | |
| 24 | return client; |
| 25 | } |
| 26 | } |
| 27 | |
View only · write via MCP/CIDE