title: MVC 3 unit testing controller but GetVirtualPathData sends strange VirtualPathData results
body: <p>I'm encountering a strange behaviour when unit testing controller.
  I'm using some extension methods for building Url.Action and all works well when runing code in production but the unit test fails.
  In fact my custom Url.Action helper is using the method :</p>
  
  <blockquote>
    <p>System.Web.Routing.RouteCollection.GetVirtualPathData</p>
  </blockquote>
  
  <p>the exact line is :</p>
  
  <blockquote>
    <p>VirtualPathData localizedPathData =
    HtmlExtensions.GetVirtualPathData(newRouteTable,
    Url.RequestContext, routingValues);</p>
    
    <p>string url =
    localizedPathData.VirtualPath.ToLower();</p>
  </blockquote>
  
  <p>The problem is that while unit testing the localizedPathData.VirtualPath is an <strong>empty string</strong> instead the url for the route like in the production code. The routingValues contains three keys "area", "controller", "action" with related values to the controller/action that I would like to have a url generated to.
  What's strange is that <em>localizedPathData.Route</em> property <strong>contains the correct route</strong> ! So why the localizedPathData.VirtualPath is an empty string ?</p>
  
  <p>I tried with GetVirtualPathForArea but the result is the same.</p>
  
  <p>I'm mocking with MvcContrib TestControllerBuilder.</p>
  
  <p>The sample code is here :</p>
  
  <pre><code>    // Arrange 
  var loginInput = new LoginInput { EmailAddress = "test@test.fr", Password = "test", RememberMe = false };
  
  new RouteConfigurator().RegisterRoutes(() =&gt; new ResumeAreaRegistration().RegisterArea(new AreaRegistrationContext("Resume", RouteTable.Routes)));
  
  var testControllerBuilder = new TestControllerBuilder(); 
  var loginController = testControllerBuilder.CreateController&lt;LoginController&gt;();
  loginController.Url = new UrlHelper(new RequestContext(loginController.HttpContext, new RouteData()), RouteTable.Routes);
  loginController.Url.RequestContext.RouteData.Values.Add("area","Resume");
  loginController.Url.RequestContext.RouteData.Values.Add("culture","en-US");
  
  const string defaultUrl = "/Dashboard";
  // act 
  
  var result = loginController.Index(loginInput, null);
  
  // assert 
  
  result.ShouldNotBeNull();
  result.AssertHttpRedirect().Url.ShouldBe(defaultUrl);
  </code></pre>
  
  <p>Maybe I'm missing something ? Something I forgot about ?</p>
  
  <p>Thank you in advance for your help.</p>