public void ShouldHaveStubbedContextCorrectly()
        {
            var context = HttpMockery.ContextForUrl("");

            context.RewritePath("");
            context.RewritePath("", "", "");
        }
        public void ShouldReturnQueryString()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar?a=b");

            var queryString = context.Request.QueryString;

            Assert.That(queryString, Is.Not.Null);
            Assert.That(queryString.Count, Is.EqualTo(1));
            Assert.That(queryString["a"], Is.EqualTo("b"));
        }
        public void ShouldReturnQueryParam()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar?a=b");

            var queryParams = context.Request.Params;

            Assert.That(queryParams, Is.Not.Null);
            Assert.That(queryParams.Count, Is.EqualTo(1));
            Assert.That(queryParams["a"], Is.EqualTo("b"));
        }
Beispiel #4
0
        public void PageControllerRouteTest()
        {
            var httpContext = HttpMockery.ContextForUrl("~/");
            var routeData   = routes.GetRouteData(httpContext);

            Assert.IsNotNull(routeData, "Did not find route");
            Assert.AreEqual("cms", (string)routeData.Values["Controller"], true);
            Assert.AreEqual("page", (string)routeData.Values["Action"], true);
            Assert.AreEqual("Containers", (string)routeData.DataTokens["Area"], true);
        }
        public void ShouldHandleMissingParamAssign()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar?a=b&c");

            var queryString = context.Request.QueryString;

            Assert.That(queryString, Is.Not.Null);
            Assert.That(queryString.Count, Is.EqualTo(2));
            Assert.That(queryString["a"], Is.EqualTo("b"));
            Assert.That(queryString["c"], Is.EqualTo(string.Empty));
        }
        public void ShouldReturnMultipleQueryParams()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar?a=b&cee=123");

            var queryParams = context.Request.Params;

            Assert.That(queryParams, Is.Not.Null);
            Assert.That(queryParams.Count, Is.EqualTo(2));
            Assert.That(queryParams["a"], Is.EqualTo("b"));
            Assert.That(queryParams["cee"], Is.EqualTo("123"));
        }
        internal static void NoRoute(RouteCollection routes, string url)
        {
            var pathUrl     = UrlHelpers.PrependTilde(url);
            var httpContext = HttpMockery.ContextForUrl(pathUrl);
            var routeData   = routes.GetRouteData(httpContext);

            if (routeData != null)
            {
                var message = string.Format("Should not have found the route to '{0}'", url);
                Asserts.Fail(message);
            }
        }
        internal static void HasRoute(RouteCollection routes, HttpMethod method, string url, string body, IDictionary <string, string> expectedProps)
        {
            var pathUrl     = UrlHelpers.PrependTilde(url);
            var httpContext = HttpMockery.ContextForUrl(method, pathUrl, body);
            var routeData   = routes.GetRouteData(httpContext);

            if (routeData == null)
            {
                var message = string.Format("Should have found the route to '{0}'", url);
                Asserts.Fail(message);
            }

            var webRouteReader = new Reader();
            var actualProps    = webRouteReader.GetRequestProperties(routeData, httpContext.Request);
            var verifier       = new Verifier();

            verifier.VerifyExpectations(expectedProps, actualProps, url);
        }
        internal static void IsNotIgnoredRoute(RouteCollection routes, string url)
        {
            var pathUrl     = UrlHelpers.PrependTilde(url);
            var httpContext = HttpMockery.ContextForUrl(pathUrl);
            var routeData   = routes.GetRouteData(httpContext);

            if (routeData == null)
            {
                var message = string.Format("Should have found the route to '{0}'", url);
                Asserts.Fail(message);
                return;
            }

            var isIgnored = (routeData.RouteHandler is StopRoutingHandler);

            if (isIgnored)
            {
                var message = string.Format("Route to '{0}' is ignored", url);
                Asserts.Fail(message);
            }
        }
        private static RequestContext RequestContext(HttpMethod httpMethod, string appPath, string requestBody)
        {
            var httpContext = HttpMockery.ContextForUrl(httpMethod, appPath, requestBody);

            return(new RequestContext(httpContext, new RouteData()));
        }
        public void ShouldReturnPathForUrl()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar");

            Assert.That(context.Request.AppRelativeCurrentExecutionFilePath, Is.EqualTo("/foo/bar"));
        }
        public void ShouldHaveEmptyPathInfo()
        {
            var context = HttpMockery.ContextForUrl("/foo/bar?a=b");

            Assert.That(context.Request.PathInfo, Is.EqualTo(string.Empty));
        }