コード例 #1
0
 public void MapShouldTakePriorityOverParameterMediaTypes()
 {
     var map = new MediaTypeFormatMap();
     map.Add("text/html", "html");
     map.Add("application/xml", "xml");
     Assert.That(map.FormatFor("application/xml", "text/html"), Is.EqualTo("html"));
 }
コード例 #2
0
 /// <summary>
 /// Creates a new ContentNegotiationRouteProxy.
 /// </summary>
 /// <param name="proxiedHandler">The handler to proxy, typically an MvcRouteHandler</param>
 /// <param name="map">The map containing the associations between media types and formats</param>
 /// <param name="priority">Whether the client sets the priority or the server.  The HTTP spec
 /// indicates that the client should set it, but on occasion the server may need to set it
 /// to work around bugs in browsers (e.g. Chrome prioritizes xml over html).</param>
 public ContentNegotiationRouteProxy(IRouteHandler proxiedHandler, MediaTypeFormatMap map,
                                     ConnegPriorityGivenTo priority = ConnegPriorityGivenTo.Client)
 {
     this.proxiedHandler = proxiedHandler;
     this.map            = map;
     this.priority       = priority;
 }
コード例 #3
0
 /// <summary>
 /// Creates a new ContentNegotiationRouteProxy.
 /// </summary>
 /// <param name="proxiedHandler">The handler to proxy, typically an MvcRouteHandler</param>
 /// <param name="map">The map containing the associations between media types and formats</param>
 /// <param name="priority">Whether the client sets the priority or the server.  The HTTP spec
 /// indicates that the client should set it, but on occasion the server may need to set it
 /// to work around bugs in browsers (e.g. Chrome prioritizes xml over html).</param>
 public ContentNegotiationRouteProxy(IRouteHandler proxiedHandler, MediaTypeFormatMap map,
     ConnegPriorityGivenTo priority = ConnegPriorityGivenTo.Client)
 {
     this.proxiedHandler = proxiedHandler;
     this.map = map;
     this.priority = priority;
 }
コード例 #4
0
        public void DefaultFormatIsFirstEntry()
        {
            var map = new MediaTypeFormatMap();
            map.Add("text/html", "html");
            map.Add("text/xml", "xml");

            Assert.That(map.DefaultFormat, Is.EqualTo("html"));
        }
コード例 #5
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);
        }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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"));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
ファイル: RouteConfig.cs プロジェクト: Raffaferreira/RestMvc
        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);
        }
コード例 #11
0
 public void ShouldReturnFormatForExactMediaType()
 {
     var map = new MediaTypeFormatMap();
     map.Add("text/html", "html");
     Assert.That(map.FormatFor("text/html"), Is.EqualTo("html"));
 }
コード例 #12
0
 public void ShouldNotSupportNonAddsedMediaTypeWithoutWildcard()
 {
     var map = new MediaTypeFormatMap();
     map.Add("text/html", "html");
     Assert.That(map.SupportsMediaType("text/plain"), Is.False);
 }
コード例 #13
0
 public void EmptyMapShouldNotHaveAnyMediaTypes()
 {
     var map = new MediaTypeFormatMap();
     Assert.That(map.SupportsMediaType("*/*"), Is.False);
 }
コード例 #14
0
 public void EmptyMapHasNoDefaultFormat()
 {
     var map = new MediaTypeFormatMap();
     Assert.That(map.DefaultFormat, Is.Null);
 }
コード例 #15
0
        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"));
        }
コード例 #16
0
        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"));
        }
コード例 #17
0
 public void ShouldReturnNullFormatIfUnsupportedMediaTypeRequested()
 {
     var map = new MediaTypeFormatMap();
     Assert.That(map.FormatFor("*/*"), Is.Null);
 }
コード例 #18
0
 public void ShouldSupportWildCardedTextMediaType()
 {
     var map = new MediaTypeFormatMap();
     map.Add("text/html", "html");
     Assert.That(map.SupportsMediaType("text/*"), Is.True);
 }
コード例 #19
0
        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"));
        }