Ejemplo n.º 1
0
        /// <summary>
        /// Gets a mock of HTML helper.
        /// </summary>
        /// <param name="applicationPath">Application path used in HTTP context.</param>
        /// <param name="routeData">Route data.</param>
        public static HtmlHelper GetHtmlHelper(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(viewContext, mockViewDataContainer));
        }
Ejemplo n.º 2
0
        /// <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()));
        }