/// <summary>
		/// allows access to things such as the controller's HttpContext, HttpContext.Request, HttpContext.Request.QueryString, HttpContext.Request.Cookies
		/// </summary>
		public static void SetMockControllerContext(this Controller yourController, HttpContextTestData httpContextTestData = null)
		{
			var request = new Mock<HttpRequestBase>();
			var response = new Mock<HttpResponseBase>();
            var requestQuery = httpContextTestData == null ? new NameValueCollection() : httpContextTestData.RequestQueryParams;
		    var reqCookies = new HttpCookieCollection();
		    var respCookies = new HttpCookieCollection();
            // controller methods might access query params either as Request.QueryString or as Request["xxx"]
            //   make Request.QueryString work:
			request.SetupGet(x => x.QueryString).Returns(requestQuery);
            //   make Request["xxx"] work:
            if (requestQuery.Count > 0)
                request.SetupGet(r => r[requestQuery.AllKeys[0]]).Returns(requestQuery.Get(0));
            if (requestQuery.Count > 1)
                request.SetupGet(r => r[requestQuery.AllKeys[1]]).Returns(requestQuery.Get(1));
            if (requestQuery.Count > 2)
                request.SetupGet(r => r[requestQuery.AllKeys[2]]).Returns(requestQuery.Get(2));
            if (requestQuery.Count > 3)
                request.SetupGet(r => r[requestQuery.AllKeys[3]]).Returns(requestQuery.Get(3));
            if (requestQuery.Count > 4)
                request.SetupGet(r => r[requestQuery.AllKeys[4]]).Returns(requestQuery.Get(4));
            request.SetupGet(x => x.Cookies).Returns(reqCookies);
		    if (httpContextTestData != null && !string.IsNullOrEmpty(httpContextTestData.Url))
		        request.SetupGet(x => x.Url).Returns(new Uri(httpContextTestData.Url));
            response.SetupGet(x => x.Cookies).Returns(respCookies);
            var context = new Mock<HttpContextBase>();
			context.SetupGet(x => x.Request).Returns(request.Object);
		    context.SetupGet(x => x.Response).Returns(response.Object);
            if (httpContextTestData != null)
                response.Setup(x => x.Redirect(It.IsAny<string>())).Callback<string>(url => httpContextTestData.RedirectUrl = url);
            yourController.ControllerContext = new ControllerContext(context.Object, new RouteData(), yourController);
		}
        /// <summary>
        /// allows access to things such as the controller's HttpContext, HttpContext.Request, HttpContext.Request.QueryString, HttpContext.Request.Cookies
        /// </summary>
        public static void SetMockControllerContext(this Controller yourController, HttpContextTestData httpContextTestData = null)
        {
            var request      = new Mock <HttpRequestBase>();
            var response     = new Mock <HttpResponseBase>();
            var requestQuery = httpContextTestData == null ? new NameValueCollection() : httpContextTestData.RequestQueryParams;
            var reqCookies   = new HttpCookieCollection();
            var respCookies  = new HttpCookieCollection();

            // controller methods might access query params either as Request.QueryString or as Request["xxx"]
            //   make Request.QueryString work:
            request.SetupGet(x => x.QueryString).Returns(requestQuery);
            //   make Request["xxx"] work:
            if (requestQuery.Count > 0)
            {
                request.SetupGet(r => r[requestQuery.AllKeys[0]]).Returns(requestQuery.Get(0));
            }
            if (requestQuery.Count > 1)
            {
                request.SetupGet(r => r[requestQuery.AllKeys[1]]).Returns(requestQuery.Get(1));
            }
            if (requestQuery.Count > 2)
            {
                request.SetupGet(r => r[requestQuery.AllKeys[2]]).Returns(requestQuery.Get(2));
            }
            if (requestQuery.Count > 3)
            {
                request.SetupGet(r => r[requestQuery.AllKeys[3]]).Returns(requestQuery.Get(3));
            }
            if (requestQuery.Count > 4)
            {
                request.SetupGet(r => r[requestQuery.AllKeys[4]]).Returns(requestQuery.Get(4));
            }
            request.SetupGet(x => x.Cookies).Returns(reqCookies);
            if (httpContextTestData != null && !string.IsNullOrEmpty(httpContextTestData.Url))
            {
                request.SetupGet(x => x.Url).Returns(new Uri(httpContextTestData.Url));
            }
            response.SetupGet(x => x.Cookies).Returns(respCookies);
            var context = new Mock <HttpContextBase>();

            context.SetupGet(x => x.Request).Returns(request.Object);
            context.SetupGet(x => x.Response).Returns(response.Object);
            if (httpContextTestData != null)
            {
                response.Setup(x => x.Redirect(It.IsAny <string>())).Callback <string>(url => httpContextTestData.RedirectUrl = url);
            }
            yourController.ControllerContext = new ControllerContext(context.Object, new RouteData(), yourController);
        }