public static ControllerContext GetErrorControllerContext(string actionName, string controllerName)
        {
            var cookie = new HttpCookieCollection();

            cookie.Add(new HttpCookie("CultureInfo", "en-GB"));
            HttpRequestBase request = new System.Web.Fakes.ShimHttpRequestBase(new StubHttpRequestBase())
            {
                CookiesGet = () => { return(cookie); }
            };
            HttpResponseBase response = new System.Web.Fakes.ShimHttpResponseBase(new StubHttpResponseBase())
            {
                CookiesGet = () => { return(cookie); }
            };

            HttpContextBase context = new System.Web.Fakes.ShimHttpContextBase(new StubHttpContextBase())
            {
                RequestGet  = () => { return(request); },
                ResponseGet = () => { return(response); }
            };

            ControllerBase baseStub = new BaseController();//
            //System.Web.Mvc.Fakes.ShimControllerBase(new StubControllerBase())
            //{

            //};

            var routeData = new System.Web.Routing.RouteData();

            routeData.Values["controller"] = controllerName;
            routeData.Values["action"]     = actionName;


            return(new ControllerContext(context, routeData, baseStub));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Mock cookies request and response
        /// </summary>
        /// <param name="useCookie"></param>
        /// <returns></returns>
        private static HttpContextBase GetControllerContext(bool useCookie)
        {
            HttpCookieCollection cookie = new HttpCookieCollection();

            if (useCookie)
            {
                cookie.Add(new HttpCookie("CultureInfo", "en-GB"));
            }


            HttpRequestBase request = new System.Web.Fakes.ShimHttpRequestBase(new StubHttpRequestBase())
            {
                CookiesGet = () => { return(cookie); },
                FormGet    = () => { return(new NameValueCollection()); },
            };

            HttpResponseBase response = new System.Web.Fakes.ShimHttpResponseBase(new StubHttpResponseBase())
            {
                CookiesGet = () => { return(cookie); }
            };

            HttpContextBase context = new System.Web.Fakes.ShimHttpContextBase(new StubHttpContextBase())
            {
                RequestGet  = () => { return(request); },
                ResponseGet = () => { return(response); }
            };



            return(context);
        }
        private static ControllerContext GetControllerContext()
        {
            var cookie = new HttpCookieCollection();

            cookie.Add(new HttpCookie("CultureInfo", "en-GB"));
            var queryString = new NameValueCollection();

            queryString.Add("error", "false");
            queryString.Add("handler", "true");
            HttpRequestBase request = new System.Web.Fakes.ShimHttpRequestBase(new StubHttpRequestBase())
            {
                CookiesGet     = () => { return(cookie); },
                FormGet        = () => { return(new NameValueCollection()); },
                QueryStringGet = () => { return(queryString); }
            };
            HttpRequestWrapper httpRequestWrapper = new System.Web.Fakes.ShimHttpRequestWrapper()
            {
                CookiesGet     = () => { return(cookie); },
                FormGet        = () => { return(new NameValueCollection()); },
                QueryStringGet = () => { return(queryString); }
            };

            HttpResponseBase response = new System.Web.Fakes.ShimHttpResponseBase(new StubHttpResponseBase())
            {
                CookiesGet = () => { return(cookie); },
            };



            HttpContextBase context = new System.Web.Fakes.ShimHttpContextBase(new StubHttpContextBase())
            {
                RequestGet  = () => { return(httpRequestWrapper); },
                ResponseGet = () => { return(response); },
                ServerGet   = () => new StubHttpServerUtilityBase
                {
                    UrlEncodeString = (url) => { return("UrlEncodeTestValue"); }
                }
            };



            ControllerBase baseStub = new BaseController();

            //new System.Web.Mvc.Fakes.ShimControllerBase(new StubControllerBase())
            //{

            //};

            var routeData = new RouteData();

            return(new ControllerContext(context, routeData, baseStub));
        }
        public static ControllerContext GetBaseControllerContext()
        {
            var cookie = new HttpCookieCollection();

            cookie.Add(new HttpCookie("CultureInfo", "en-GB"));
            var             cultureInfo = new HttpCookie("CultureInfo", "en-GB");
            HttpRequestBase request     = new System.Web.Fakes.ShimHttpRequestBase(new StubHttpRequestBase())
            {
                CookiesGet = () => { return(cookie); }
            };
            HttpResponseBase response = new System.Web.Fakes.ShimHttpResponseBase(new StubHttpResponseBase())
            {
                CookiesGet = () => { return(cookie); }
            };

            HttpServerUtilityBase untilityBase = new System.Web.Fakes.ShimHttpServerUtilityBase(new StubHttpServerUtilityBase())
            {
                UrlEncodeString = (info) => { return(cultureInfo.ToString()); }
            };

            HttpContextBase context = new System.Web.Fakes.ShimHttpContextBase(new StubHttpContextBase())
            {
                RequestGet  = () => { return(request); },
                ResponseGet = () => { return(response); },
                ServerGet   = () => { return(untilityBase); }
            };

            ControllerBase baseStub = new BaseController();//new System.Web.Mvc.Fakes.ShimControllerBase(new StubControllerBase())
            //{

            //};

            var routeData = new RouteData();



            return(new ControllerContext(context, routeData, baseStub));
        }