* Separate ASP.NET Core tests into a distinct project and make the main test project netfx compatible. * Fix merge conflicts. * Update tests/ModelContextProtocol.Tests/ModelContextProtocol.Tests.csproj Co-authored-by: Stephen Halter <halter73@gmail.com> * Revert "Fix merge conflicts." This reverts commit 852169b96786bad2144795540fa164e20b4b197e. * Fix merge conflicts --------- Co-authored-by: Stephen Halter <halter73@gmail.com>
20 lines
736 B
C#
20 lines
736 B
C#
namespace ModelContextProtocol.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.");
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
var result = await RequestHandler.Invoke(request);
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
return result;
|
|
}
|
|
}
|