i'm doing unit test with NUnit and NSubstitue at the project which uses a GraphQL for an API. The Client of GraphQL is an object and I try it to mock but I don't know how.
I have a Handler to override SensAsync
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
return await Task.FromResult(_mockResponse);
}
Is there a way to easily mock the object GraphQLHttpClient in unit tests?
You can mock an
HttpClientandHttpMessageHandlerinstances and use them to initialize yourGraphQLHttpClient. You can check the answer here.