Someone asked me a question recently about mocking, and I had to say I didn’t have much experience with it. I found this answer a bit odd myself as I’ve been doing a lot of TDD with an ASP.Net MVC application. I’d seen lots of people talking about mocking the HttpContext and wondered “Why haven’t I had to do this?”.
public class ActionInvoker : ControllerActionInvoker
{
protected override object GetParameterValue(System.Reflection.ParameterInfo parameterInfo)
{
if (parameterInfo.ParameterType == typeof(IPrincipal))
return HttpContext.Current.User;
return base.GetParameterValue(parameterInfo);
}
}
public MyController()
{
ActionInvoker = new ActionInvokers.ActionInvoker();
}

#1 by Webmonkey-in-Ireland on June 10, 2009 - 20:28
Hi Trevor, thanks for the Twitter follow.
Just in case it helps- you can fully mock HttpContext with TypeMock. Its not free, but does a good job with this sort of thing.