title: How to create mock HTTP post request with a JSON body using Moq
body: <p>I'm trying to do basically what the title says in order to unit test my api controller,  but I have problems finding the proper way and can't afford spending too much time on this. Here is my code.</p>
  
  <pre><code>[TestMethod]
  public void Should_return_a_valid_json_result()
  {
      // Arrange
      Search search = new Search();
      search.Area = "test";
      string json = JsonConvert.SerializeObject(search);
  
      var context = new Mock&lt;HttpContextBase&gt;();
      var request = new Mock&lt;HttpRequestBase&gt;();
  
      request.Setup(r =&gt; r.HttpMethod).Returns("POST");
      request.Setup(r =&gt; r.InputStream.ToString()).Returns(json);
  
      context.Setup(c =&gt; c.Request).Returns(request.Object);
  
      var controller = new UserController();
      controller.ControllerContext = new HttpControllerContext() {  RequestContext = context };
  
     //more code
  
  }
  </code></pre>
  
  <blockquote>
    <p>Last line returns Error   CS0029  Cannot implicitly convert type
    'Moq.Mock System.Web.HttpContextBase' to
    'System.Web.Http.Controllers.HttpRequestContext'.</p>
  </blockquote>
  
  <p>I am also not sure about the Moq syntax I should use, other questions,examples and Moq Documentation didn't help me much.</p>