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();
}
