title: Can I mock httpClient.PostAsync() call without a wrapper?
body: <p>I am using Moq for writing tests and am able to mock the HttpClientHandler for the GetAsync() call but when I try to mock a PostAsync() it returns null. Is there a way to mock that functionality without creating a wrapper around the whole HttpClient?</p>
  
  <p>Below is my unit test code for mocking the function. </p>
  
  <pre><code>Mock&lt;WebProxy&gt; mockWebProxy = new Mock&lt;WebProxy&gt;();
          mockWebProxy.Object.Address = new Uri(configuration.GetSection("TestProxy").Value);
          mockWebProxy.Object.UseDefaultCredentials = true;
          Mock&lt;HttpClient&gt; mockHttpClient = new Mock&lt;HttpClient&gt;();
          var mockHttpClientHandler = new Mock&lt;HttpClientHandler&gt;();
          mockHttpClientHandler.Object.Proxy = mockWebProxy.Object;
          mockHttpClientHandler
              .Protected()
              .Setup&lt;Task&lt;HttpResponseMessage&gt;&gt;(
                  "SendAsync",
                  ItExpr.IsAny&lt;HttpRequestMessage&gt;(),
                  ItExpr.IsAny&lt;CancellationToken&gt;()
              )
              .ReturnsAsync(new HttpResponseMessage()
              {
                  StatusCode = HttpStatusCode.OK,
                  Content = new StringContent("this is a test")
              })
              .Verifiable();
          mockHttpClient = new Mock&lt;HttpClient&gt;(mockHttpClientHandler.Object, true);
  </code></pre>
  
  <p>Then here is me calling the PostAsync():</p>
  
  <pre><code>var response = await httpClient.PostAsync(new Uri(url), stringContent);
  </code></pre>
  
  <p>The PostAsync() works when not mocking the httpClient. But when mocking, the response above is null. That tells me the mocked HttpClient is being used since there is no response but I am not sure why it is null and not the HttpResponseMessage I mocked which works for GetAsync().</p>