/// <summary> /// Gets a mock of a generic HTML helper. /// </summary> /// <param name="applicationPath">Application path used in HTTP context.</param> /// <param name="routeData">Route data.</param> /// <param name="textWriter">Text writer.</param> public static HtmlHelper <TModel> GetHtmlHelper <TModel>(string applicationPath = "/", RouteData routeData = null, TextWriter textWriter = null) { textWriter = textWriter ?? Substitute.For <TextWriter>(); var context = HttpContextMock.GetHttpContext(applicationPath); var viewDataDictionary = new ViewDataDictionary(); var controllerContext = new ControllerContext(context, routeData ?? new RouteData(), Substitute.For <ControllerBase>()); var viewContext = new ViewContext(controllerContext, Substitute.For <IView>(), viewDataDictionary, new TempDataDictionary(), textWriter); var mockViewDataContainer = Substitute.For <IViewDataContainer>(); mockViewDataContainer.ViewData.Returns(viewDataDictionary); return(new HtmlHelper <TModel>(viewContext, mockViewDataContainer)); }
/// <summary> /// Gets a mock of <see cref="RequestContext"/>. /// </summary> /// <param name="applicationPath">Application path used in context.</param> /// <param name="routeData">Route data.</param> public static RequestContext GetRequestContext(string applicationPath = "/", RouteData routeData = null) { var httpContext = HttpContextMock.GetHttpContext(applicationPath); return(new RequestContext(httpContext, routeData ?? new RouteData())); }