title: How to Mock IUrlHelper
body: <p>Getting started with Unit Tests can be frustrating, getting stuck at every detail. Hope this will improve as I gain more experience.</p>
  
  <p>Now, how do I  mock <code>IUrlHelper</code> for unit test?</p>
  
  <p>I have this simple method to get absolute paths in ASP.NET</p>
  
  <pre><code>public static string AbsolutePage(this IUrlHelper url, string pageName, string pageHandler = null, object routeValues = null)
  {
      return url.Page(pageName, pageHandler, routeValues, url.ActionContext.HttpContext.Request.Scheme);
  }
  </code></pre>
  
  <p>Mocking the Scheme is easy</p>
  
  <pre><code>return Mock.Of&lt;IUrlHelper&gt;(x =&gt;
      x.ActionContext.HttpContext.Request.Scheme == "http");
  </code></pre>
  
  <p>but then the method calls the Page method on the <code>IUrlHelper</code>. What do I do now?</p>
  
  <p>I'd be tempted to skip small frustrating tests like this, but I think it's important to be vigorous when first learning.</p>