I am getting the error:
System.ArgumentException: Method HttpClient.SendAsync is public. Use strong-typed Expect overload instead: mock.Setup(x => x.SendAsync());
While trying to run the following code:
autoMock.Mock<HttpClient>()
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(httpResponseMessage)
.Verifiable();
What may I be missing here?
HttpRequestHandler:(You might need to pass
MockBehavior.Strictto theMock<T>ctor)mockedHandlerwhen you instantiate theHttpClientinstanceIt is worth to take look at the MockHttp library, it makes your mocking lot easier.