Path: redb-route/tests/redb.Route.Tests.Llm.Mcp/Framing/TestableMcpClient.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Llm.Mcp/Framing/TestableMcpClient.cs
----
using Microsoft.Extensions.Logging.Abstractions;
using redb.Route.Llm.Mcp.Protocol;
namespace redb.Route.Tests.Llm.Mcp.Framing;
///
/// Test subclass that exposes the protected hooks of
/// and captures every outgoing frame so we can assert on what the client sent.
///
internal sealed class TestableMcpClient : McpClientBase
{
public List SentFrames { get; } = new();
public TaskCompletionSource StartTransportTcs { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public TaskCompletionSource StopTransportTcs { get; } = new(TaskCreationOptions.RunContinuationsAsynchronously);
public TestableMcpClient(string serverName)
: base(serverName, NullLogger.Instance) { }
public void InjectFrame(string frameJson) => OnFrameReceived(frameJson);
public void InjectTransportFailure(string reason) => OnTransportFailed(reason);
protected override Task StartTransportAsync(CancellationToken cancellationToken)
{
StartTransportTcs.TrySetResult();
return Task.CompletedTask;
}
protected override Task StopTransportAsync()
{
StopTransportTcs.TrySetResult();
return Task.CompletedTask;
}
protected override Task SendFrameAsync(string frameJson, CancellationToken cancellationToken)
{
lock (SentFrames) SentFrames.Add(frameJson);
return Task.CompletedTask;
}
}