You won't be able to test that method, since it's using
HttpContext.Current
.
You should change the method so that you pass in an
HttpContextBase
instance - or preferably a
RequestContext
instance - as a parameter.
public static string RenderViewToString(RequestContext requestContext, string viewPath, object model = null)
{
var context = new ControllerContext(requestContext, new MyController());
...
Code that calls it from within a controller can pass in the controller's
ControllerContext.RequestContext
instance.
Code that calls it from a static method can pass in
HttpContext.Current.Request.RequestContext
, or be modified to accept the
RequestContext
as a parameter.
Your unit test code then only needs to mock the
RequestContext
object.