UrlHelper mock is not working
<p>I am trying to write get write a unit test that passes but the method my test calls, calls another method which generates a URL using the <code>UrlHelper</code> class. The result of calling <code>urlHelper.Action</code> keeps returning <code>null</code>. </p>

<p>I have tried mocking (using Moq) all the components i assume this controller will need to be able to get this working, but I am still getting <code>null</code>.</p>

<p><strong>Unit Test Class</strong></p>

<pre><code>[TestFixtureSetUp]
public void Configure_Defaults()
{

    var mockHttpContextBase = new Mock&lt;HttpContextBase&gt;();

    var mockRequest = new Mock&lt;HttpRequestBase&gt;();

    var mockControllerContext = new Mock&lt;ControllerContext&gt;();

    var mockWebRoutingRequestContrext = new Mock&lt;RequestContext&gt;();

    mockRequest
        .Setup(request =&gt; request.Url)
        .Returns(new Uri("http://dev.fleepos.local/Register"));

    mockHttpContextBase
        .Setup(httpContext =&gt; httpContext.Request)
        .Returns(mockRequest.Object);

    mockWebRoutingRequestContrext
        .Setup(request =&gt; request.HttpContext)
        .Returns(mockHttpContextBase.Object);

    mockWebRoutingRequestContrext
        .Setup(request =&gt; request.RouteData)
        .Returns(new RouteData());

    var urlHelper = new UrlHelper(mockWebRoutingRequestContrext.Object);

    mockControllerContext
        .Setup(controllerContext =&gt; controllerContext.HttpContext)
        .Returns(mockHttpContextBase.Object);


    _registerController = new RegisterController() {ControllerContext = mockControllerContext.Object, Url = urlHelper};

}

[Test]
public void Display_Validate_Account_Page_On_Successful_Registration()
{
    //act
    var result = (RedirectToRouteResult)_registerController.Register(_userRegisterationViewModel);

    //assert
    Assert.That(result.RouteValues["action"], Is.EqualTo("ValidateAccount"));
}
</code></pre>

<p><strong>Controller method called by controller action</strong></p>

<pre><code>private string GenerateActionLink(string actionName, string token, string username)
{
    string validationLink = null;
    if (Request.Url != null)
    {
        var urlHelper = new UrlHelper(ControllerContext.RequestContext);
        validationLink = urlHelper.Action(actionName, "Register",
            new { Token = token, Username = username },
            Request.Url.Scheme);
    }

    return validationLink;
}
</code></pre>