public void WhenCalledPaymentGateway_ReturnsPaymentIsSuccessful() { var mockHandler = new Mock <HttpMessageHandler>(); var requestUri = "http://www.google.com/search?q=7.0"; var response = new HttpResponseMessage { StatusCode = HttpStatusCode.OK }; mockHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(response); var httpClient = new HttpClient(mockHandler.Object); var paymentGateway = new PaymentGateway(httpClient); var retrievedPosts = paymentGateway.GetAsync(requestUri); Assert.NotNull(retrievedPosts); mockHandler.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get), ItExpr.IsAny <CancellationToken>()); }