Improve code coverage (#40)

* Add tests for tool generation

* Add couple of MCPServer tests

* Fix merge issues

* More tests for McpServer

* Some more tests

* Fix merge issues
This commit is contained in:
Toni Wenzel 2025-03-10 18:19:49 +01:00 • committed by GitHub
commit 24c706b4ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,22 @@
namespace McpDotNet.Tests.Utils;
public class MockHttpHandler : HttpMessageHandler
{
public Func<HttpRequestMessage, Task<HttpResponseMessage>>? RequestHandler { get; set; }
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (RequestHandler == null)
throw new InvalidOperationException($"No {nameof(RequestHandler)} was set! Please set handler first and make request afterwards.");
if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
var result = await RequestHandler.Invoke(request);
if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
return result;
}
}