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); }
/// <summary> /// The get shim http context base, used for tests. Must be encapsulated in /// using (ShimsContext.Create()) /// {} /// statement. /// </summary> /// <param name="useCookie"> /// Set to true if cookies are used. /// </param> /// <returns> /// Shimmed httpContextBase. <see cref="HttpContextBase"/>. /// </returns> private static HttpContextBase GetStubHttpContextBase(bool useCookie = true) { var cookie = new HttpCookieCollection(); cookie.Add(new HttpCookie("CultureInfo", "en-GB")); var queryString = new NameValueCollection(); queryString.Add("error", "false"); queryString.Add("handler", "true"); var cultureInfo = new HttpCookie("CultureInfo", "en-GB"); if (useCookie) { cookie.Add(cultureInfo); } HttpRequestBase stubHttpRequestBase = new System.Web.Fakes.StubHttpRequestBase() { CookiesGet = () => { return(cookie); }, FormGet = () => { return(new NameValueCollection()); }, QueryStringGet = () => { return(queryString); } }; // Might be needed? instead of stubHttpRequestBase: HttpRequestWrapper httpRequestWrapper = new System.Web.Fakes.ShimHttpRequestWrapper() // { // CookiesGet = () => { return cookie; }, // FormGet = () => { return new NameValueCollection(); }, // QueryStringGet = () => { return queryString; } // }; HttpResponseBase response = new System.Web.Fakes.StubHttpResponseBase() { CookiesGet = () => { return(cookie); } }; HttpServerUtilityBase untilityBase = new System.Web.Fakes.StubHttpServerUtilityBase() { UrlEncodeString = (info) => { return(cultureInfo.ToString()); } }; HttpContextBase stubHttpContext = new System.Web.Fakes.StubHttpContextBase() { RequestGet = () => { return(stubHttpRequestBase); }, ResponseGet = () => { return(response); }, ServerGet = () => { return(untilityBase); } }; return(stubHttpContext); }