title: Mock ControllerBase Request using Moq
body: <p>I have a Web API in .Net Core 2.2 as below:</p>
  
  <pre><code>[Authorize]
  [Route("api/[controller]")]
  [ApiController]
  public class SomeController : ControllerBase
  {
      [HttpPost]
      public async Task&lt;string&gt; SomeMethodPost()
      {
          string returnUrl = $"{this.Request.Scheme}://{this.Request.Host}{this.Request.PathBase}/some/redirect";
  
          //Some Third Part Service Call
  
          return serviceResult;
      }
  }
  </code></pre>
  
  <p>I want to mock the properties "Scheme", "Host" and "PathBase" for my controller action in my unit test. I managed to write below code in my unit test method:</p>
  
  <pre><code>var request = new Mock&lt;HttpRequest&gt;(MockBehavior.Strict);
  request.Setup(x =&gt; x.Scheme).Returns("http");
  request.Setup(x =&gt; x.Host).Returns(HostString.FromUriComponent("http://localhost:8080"));
  request.Setup(x =&gt; x.PathBase).Returns(PathString.FromUriComponent("/api"));
  
  var mockHttp = new Mock&lt;ControllerBase&gt;(MockBehavior.Strict);
  mockHttp.SetupGet(x =&gt; x.Request).Returns(request.Object);
  </code></pre>
  
  <p>However, the mock in last line throws exception as "<code>Request</code>" of "<code>ControllerBase</code>" is non overridable. I understand the limitation with non virtual properties of abstract classes. Is there any workaround for this? </p>
  
  <p>Moq version is 4.13.0.</p>