Example #1
0
        /// <summary>
        /// Swap in a dummy HttpContext for HttpContext.Current, valid for current thread only
        /// </summary>
        internal static void SubstituteDummyHttpContext(string location, HttpBrowserCapabilities caps = null)
        {
            var workerRequest = new TestHttpWorkerRequest(location);
            var testContext   = new HttpContext(workerRequest);

            // BrowserCapabilities
            caps = caps ?? BrowserDefinitions.DEFAULT;
            testContext.Request.SetBrowserCaps(caps);

            testContext.Items["IsInTestMode"] = true;

            HttpContext.Current = testContext;
        }
        private static HttpContext GetTestContext(string location)
        {
            var workerRequest = new TestHttpWorkerRequest(location);
            var testContext   = new HttpContext(workerRequest);

            // BrowserCapabilities
            HttpBrowserCapabilities caps = GetBrowserCaps();

            typeof(HttpRequest).GetField("_browsercaps", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(testContext.Request, caps);

            testContext.Items["IsInTestMode"] = true;

            return(testContext);
        }