/// <summary>
        /// Gets a shim controller context, used for tests. Must be encapsulated in
        /// using (ShimsContext.Create())
        /// {}
        /// statement.
        /// </summary>
        /// <param name="actionName">
        /// The action name.
        /// </param>
        /// <param name="controllerName">
        /// The controller name.
        /// </param>
        /// <param name="useCookie">
        /// The used cookie.
        /// </param>
        /// <returns>
        /// A shimmed controller context. <see cref="ControllerContext"/>.
        /// </returns>
        public static ControllerContext GetShimControllerContext(string actionName, string controllerName, bool useCookie = true)
        {
            HttpContext     shimHttpContext     = GetShimHttpContext(useCookie);
            HttpContextBase shimHttpContextBase = new HttpContextWrapper(shimHttpContext);

            ControllerBase baseStub  = new DyntaxaBaseController();//new BaseController();
            var            routeData = new RouteData();

            routeData.Values["controller"] = controllerName;
            routeData.Values["action"]     = actionName;
            return(new ControllerContext(shimHttpContextBase, routeData, baseStub));
        }
Esempio n. 2
0
        public void EncodeDecodeQueryStringTest()
        {
            DyntaxaBaseController controller = new DyntaxaBaseController();
            RouteValueDictionary  dic        = new RouteValueDictionary();

            dic.Add("mode", "full");
            dic.Add("search", "hästar och fåglar");
            string encodedQueryString = controller.EncodeRouteQueryString(dic);

            RouteValueDictionary dicDecoded = controller.DecodeRouteQueryString(encodedQueryString);

            Assert.AreEqual("full", dicDecoded["mode"]);
            Assert.AreEqual("hästar och fåglar", dicDecoded["search"]);
        }
        /// <summary>


        //public static HttpControllerContext GetShimHttpControllerContext(string apiUri, string actionName, string controllerName)
        //{
        //    HttpConfiguration configuration = new HttpConfiguration();
        //    HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/" + apiUri);
        //    IHttpRoute route = configuration.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
        //    HttpRouteData routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", controllerName }, { "action", actionName } });

        //    return new HttpControllerContext(configuration, routeData, requestMessage);
        //}

        /// <summary>
        /// Gets a shim account controller context, used for tests. Must be encapsulated in
        /// using (ShimsContext.Create())
        /// </summary>
        /// <param name="controller">
        /// Account controller to be shimmed.
        /// </param>
        /// <param name="actionName">
        /// The action Name.
        /// </param>
        /// <param name="useCookie">
        /// Set cookie if required.
        /// </param>
        protected void GetShimAccountControllerContext(AccountController controller, string actionName, bool useCookie = true)
        {
            HttpContext     shimHttpContext     = GetShimHttpContext(useCookie);
            HttpContextBase shimHttpContextBase = new HttpContextWrapper(shimHttpContext);
            ControllerBase  baseStub            = new DyntaxaBaseController();

            FormsAuthenticationService formsAuthenticationServiceMock = new FormsAuthenticationService();//new ShimFormsAuthenticationService() { };

            controller.FormsService = formsAuthenticationServiceMock;
            var requestContext = new RequestContext(shimHttpContextBase, new RouteData());

            controller.Url = new UrlHelper(requestContext);

            var routeData = new RouteData();

            routeData.Values["controller"] = "Account";
            routeData.Values["action"]     = actionName;

            controller.ControllerContext = new ControllerContext(shimHttpContextBase, routeData, baseStub);
        }