Beispiel #1
0
        protected void Application_Start()
        {
            var map = new MediaTypeFormatMap();
            map.Add(MediaType.PlainText, "text");
            map.Add(MediaType.Xml, "xml");
            var connegHandler = new ContentNegotiationRouteProxy(new MvcRouteHandler(), map);

            RouteTable.Routes.MapAssembly(Assembly.GetExecutingAssembly(), connegHandler);
        }
        public void ShouldMapMediaTypeToFormat()
        {
            var map = new MediaTypeFormatMap();
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();

            router.AddFormat(route, new[] {"*/*"});

            Assert.That(route.Values["format"], Is.EqualTo("xml"));
        }
        public void ShouldPrioritizeFormatSelectionByAcceptTypeOrderingByDefault()
        {
            var map = new MediaTypeFormatMap();
            map.Add("application/xml", "xml");
            map.Add("text/html", "html");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();

            router.AddFormat(route, new[] {"text/html", "application/xml"});

            Assert.That(route.Values["format"], Is.EqualTo("html"));
        }
        public void ShouldNotSetFormatIfRoutingSystemAlreadyDetectedIt()
        {
            var map = new MediaTypeFormatMap();
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();
            route.Values["format"] = "html";

            router.AddFormat(route, new[] {"*/*"});

            Assert.That(route.Values["format"], Is.EqualTo("html"));
        }
        public void ShouldIgnoreUnsupportedMediaTypes()
        {
            var map = new MediaTypeFormatMap();
            map.Add("text/plain", "text");
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();

            router.AddFormat(route, new[] {"text/html", "application/xml"});

            Assert.That(route.Values["format"], Is.EqualTo("xml"));
        }
        public void GetHandlerProxiesToPassedInHandler()
        {
            var proxiedHandler = new Mock<IRouteHandler>();
            var httpContext = new Mock<HttpContextBase>();
            httpContext.Setup(ctx => ctx.Request.AcceptTypes).Returns(new string[0]);
            var request = new RequestContext(httpContext.Object, new RouteData());
            var router = new ContentNegotiationRouteProxy(proxiedHandler.Object, new MediaTypeFormatMap());

            router.GetHttpHandler(request);

            proxiedHandler.Verify(h => h.GetHttpHandler(request));
        }
Beispiel #7
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //routes.MapRoute(
            //    name: "Default",
            //    url: "{controller}/{action}/{id}",
            //    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            //);

            // Routes are generated by RestMvc using reflection to inspect controller attributes.
            // Other routes could also be added here manually.

            var map = new MediaTypeFormatMap();
            map.Add(MediaType.PlainText, "text");
            map.Add(MediaType.Xml, "xml");
            var connegHandler = new ContentNegotiationRouteProxy(new MvcRouteHandler(), map);
            routes.MapAssembly(Assembly.GetExecutingAssembly(), connegHandler);
        }
        public void ShouldPrioritizeFormatSelectionByMapEntriesIfAskedTo()
        {
            var map = new MediaTypeFormatMap();
            map.Add("text/html", "html");
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map, ConnegPriorityGivenTo.Server);
            var route = new RouteData();

            router.AddFormat(route, new[] {"application/xml", "text/html"});

            Assert.That(route.Values["format"], Is.EqualTo("html"));
        }
        public void UnsupportedAcceptTypeMapsToDefaultFormat()
        {
            var map = new MediaTypeFormatMap();
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();

            router.AddFormat(route, new[] {"audio/*"});

            Assert.That(route.Values["format"], Is.EqualTo("xml"));
        }
        public void ShouldUseDefaultFormatIfNullAcceptTypesProvided()
        {
            var map = new MediaTypeFormatMap();
            map.Add("application/xml", "xml");
            var router = new ContentNegotiationRouteProxy(null, map);
            var route = new RouteData();

            router.AddFormat(route, null);

            Assert.That(route.Values["format"], Is.EqualTo("xml"));
        }