public static HttpContext GetFakeHttpContext(IDictionary<string, string> headers = null)
        {
            Thread.GetDomain().SetData(".appPath", string.Empty);
            Thread.GetDomain().SetData(".appVPath", string.Empty);

            var workerRequest = new SimpleWorkerRequestWithHeaders(UrlPath, UrlQueryString, new StringWriter(CultureInfo.InvariantCulture), headers);
            
            return new HttpContext(workerRequest);
        }
        public static HttpContext GetFakeHttpContext(IDictionary <string, string> headers = null)
        {
            Thread.GetDomain().SetData(".appPath", string.Empty);
            Thread.GetDomain().SetData(".appVPath", string.Empty);

            var workerRequest = new SimpleWorkerRequestWithHeaders(UrlPath, UrlQueryString, new StringWriter(CultureInfo.InvariantCulture), headers);

            return(new HttpContext(workerRequest));
        }
        public static HttpContext GetFakeHttpContext(string page = "/page", string query = "", IDictionary <string, string> headers = null)
        {
            Thread.GetDomain().SetData(".appPath", string.Empty);
            Thread.GetDomain().SetData(".appVPath", string.Empty);

            var workerRequest = new SimpleWorkerRequestWithHeaders(page, query, new StringWriter(CultureInfo.InvariantCulture), headers);
            var context       = new HttpContext(workerRequest);

            HttpContext.Current = context;
            return(context);
        }
Пример #4
0
        /// <summary>
        /// Sets the static HttpContext.Current for use in unit tests.
        /// Request URL is set specifically to evaluate httpContext.Request.Url during tests.
        /// </summary>
        public static HttpContext SetFakeHttpContext(IDictionary <string, string> headers = null, Func <string> remoteAddr = null)
        {
            string urlPath        = "/SeLog.svc/EventData";
            string urlQueryString = "eventDetail=2";

            Thread.GetDomain().SetData(".appPath", string.Empty);
            Thread.GetDomain().SetData(".appVPath", string.Empty);

            var workerRequest = new SimpleWorkerRequestWithHeaders(urlPath, urlQueryString, new StringWriter(CultureInfo.InvariantCulture), headers, remoteAddr);

            var context = new HttpContext(workerRequest);

            HttpContext.Current = context;

            return(context);
        }