title: Unit tests with NUnit for controller actions
body: <p>I am building a REST API and have some controllers, that i would like to test. The problem is, for post methods, i need to mock the http request.</p>
  
  <p>My post method within the controller looks like this:</p>
  
  <pre><code>    [HttpPost]
      public async Task&lt;IActionResult&gt; Post([FromBody] xxx xxx)
      {
         ...
  
         return Ok(new Link()
         {
             Id = ...,
             Href = GetPath(id)
         });
     }
  
  
  private string GetPath(int id)
      {
          var displayUrl = UriHelper.GetDisplayUrl(Request);
          var urlBuilder = new UriBuilder(displayUrl)
          {
              Query = null,
              Fragment = null
          };
          return urlBuilder.ToString() + "/" + id;
      }
  </code></pre>
  
  <p>As you can see inside the GetPath function there is Request. This is always null and throws errors, when executing the unit test.</p>
  
  <p>My unit test so far (with mocked database):</p>
  
  <pre><code>[Test]
      public async Task PostAsync_ReturnsHttpStatus200()
      {
          SaveObject object= new SaveObject
          {
              ...
          };
  
          var response = await controller.PostAsync(object);
  
          Assert.That(response, Is.InstanceOf(typeof(OkObjectResult)));
      }
  </code></pre>
  
  <p>I will not show the one time setup, as all the other parts of the unit test seem to work, only the previously explained problem does exist.</p>
  
  <p>How do i mock the request with ASP.Net Core (.Net Core 3.1)?</p>