Exemplo n.º 1
0
        public void UrlWithNoQueryParamsIsParsed()
        {
            const string Url = "/foo/bar";

            var parsedParams = UrlHelpers.MakeQueryParams(Url);

            Assert.That(parsedParams.Count, Is.EqualTo(0));
        }
Exemplo n.º 2
0
        public void UrlWithOneQueryParamsIsParsed()
        {
            const string Url = "/foo/bar?id=3";

            var parsedParams = UrlHelpers.MakeQueryParams(Url);

            Assert.That(parsedParams.Count, Is.EqualTo(1));
            Assert.That(parsedParams["id"], Is.EqualTo("3"));
        }
Exemplo n.º 3
0
        public void UrlWithTwoQueryParamsIsParsed()
        {
            const string Url = "/foo/bar?name=fish&fish=trout";

            var parsedParams = UrlHelpers.MakeQueryParams(Url);

            Assert.That(parsedParams.Count, Is.EqualTo(2));
            Assert.That(parsedParams["name"], Is.EqualTo("fish"));
            Assert.That(parsedParams["fish"], Is.EqualTo("trout"));
        }
Exemplo n.º 4
0
        public static HttpContextBase ContextForUrl(HttpMethod method, string url, string requestBody)
        {
            var routeParts  = url.Split('?');
            var relativeUrl = routeParts[0];
            var queryParams = UrlHelpers.MakeQueryParams(url);


            var request     = new MockHttpRequest(method, relativeUrl, queryParams, requestBody);
            var httpContext = new MockHttpContext(request);

            var requestContext = new RequestContext(httpContext, new RouteData());

            request.SetContext(requestContext);

            return(httpContext);
        }
Exemplo n.º 5
0
        public IDictionary <string, string> ReadRequestProperties(string url, HttpMethod httpMethod)
        {
            if (!CheckValid(url, httpMethod))
            {
                return(new Dictionary <string, string>());
            }

            var actualProps = new Dictionary <string, string>
            {
                { "controller", ControllerName() },
                { "action", ActionName() }
            };

            var routeParams = GetRouteParams();

            foreach (var paramKey in routeParams.Keys)
            {
                actualProps.Add(paramKey, routeParams[paramKey]);
            }

            var queryParams = UrlHelpers.MakeQueryParams(url);

            foreach (var key in queryParams.AllKeys)
            {
                if (actualProps.ContainsKey(key))
                {
                    actualProps[key] = queryParams[key];
                }
                else
                {
                    actualProps.Add(key, queryParams[key]);
                }
            }

            ReadPropertiesFromBodyContent(actualProps);

            return(actualProps);
        }