public static HttpContextBase GetAccountControllerContext(bool useCookie = true) { var cookie = new HttpCookieCollection(); if (useCookie) { cookie.Add(new HttpCookie("CultureInfo", "en-GB")); } var cultureInfo = new HttpCookie("CultureInfo", "en-GB"); HttpRequestBase stubHttpRequestBase = new System.Web.Fakes.StubHttpRequestBase() { CookiesGet = () => { return(cookie); }, }; HttpResponseBase response = new System.Web.Fakes.StubHttpResponseBase() { CookiesGet = () => { return(cookie); } }; HttpServerUtilityBase untilityBase = new System.Web.Fakes.ShimHttpServerUtilityBase(new StubHttpServerUtilityBase()) { UrlEncodeString = (info) => { return(cultureInfo.ToString()); } }; HttpContextBase stubHttpContext = new System.Web.Fakes.StubHttpContextBase() { RequestGet = () => { return(stubHttpRequestBase); }, ResponseGet = () => { return(response); }, ServerGet = () => { return(untilityBase); } }; return(stubHttpContext); }
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)); }