title: Is this a bug in the MvcContrib TestHelper OutBoundUrl class?
body: <p>I am trying to test the outbound URL of an action method in an MVC area using the MvcContrib TestHelper's static <code>OutBoundUrl</code> class. Here is what I have:</p>
  
  <pre><code>OutBoundUrl.Of&lt;ErrorsController&gt;(action =&gt; action.NotFound())
      .ShouldMapToUrl("/errors/404");
  </code></pre>
  
  <p>I stepped into the source and found that the <code>UrlHelper</code> was returning null for the outbound URL. Basically it creates a new UrlHelper and delegates the task to <code>UrlHelper.Action(action, controller, routeValues)</code>. </p>
  
  <p>When invoked, <code>routeValues</code> does not contain anything (the action method takes no args). Is this a bug? Or do I need to do something extra to make this work with areas? The following line comes just before the above line in the unit test, so my routes are registered (the <code>UrlHelper.RouteCollection</code> contains 100+ routes).</p>
  
  <pre><code>"~/errors/404".WithMethod(HttpVerbs.Get)
      .ShouldMapTo&lt;ErrorsController&gt;(action =&gt; action.NotFound());
  </code></pre>
  
  <p>The route is not named, and I don't want to name it, so please don't suggest I use the <code>OfRouteNamed</code> method.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I made an extension method that could work, except for one thing. The <code>OutBoundController</code> <code>Of&lt;TController&gt;</code> method has this code:</p>
  
  <pre><code>var methodCall = ((MethodCallExpression)action.Body);
  var methodName = methodCall.Method.Name;
  </code></pre>
  
  <p>There is similar, but critically different code in the <code>RouteTestingExtensions</code> <code>ShouldMapTo&lt;TController&gt;</code> method:</p>
  
  <pre><code>var methodCall = (MethodCallExpression) action.Body;
  // this line is not important
  string expectedAction = methodCall.Method.ActionName();
  </code></pre>
  
  <p>The <code>ActionName()</code> extension method is kind of awesome if you use <code>ActionNameAttributes</code>:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Will return the name of the action specified in the ActionNameAttribute 
  /// for a method if it has an ActionNameAttribute.
  /// Will return the name of the method otherwise.
  /// &lt;/summary&gt;
  /// &lt;param name="method"&gt;&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  public static string ActionName(this MethodInfo method)
  {
      if (method.IsDecoratedWith&lt;ActionNameAttribute&gt;()) 
          return method.GetAttribute&lt;ActionNameAttribute&gt;().Name;
  
      return method.Name;
  }
  </code></pre>
  
  <p>Back to the question... is this by design, and if so, why? The fact that <code>OutBoundUrl</code> does not use the <code>.ActionName()</code> extension is the one thing keeping me from writing an extension method to generate outbound url's for area actions decorated with <code>[ActionName]</code>.</p>