public void Specific_media_type_select_highest_ranked() { var jsonHigherPriorityXmlLowerPriorityAccepted = "application/xml;q=0.8, application/json"; var selector = new ResponseMediaTypeSelector(jsonHigherPriorityXmlLowerPriorityAccepted); var selected = selector.SelectType(new[] { ContentMediaType.Xml, ContentMediaType.Json }); Assert.Equal(ContentMediaType.Json, selected); }
public void Generic_media_type_select_by_order_of_media_type() { var xmlAndJsonSuperTypeAccepted = "application/*"; var selector = new ResponseMediaTypeSelector(xmlAndJsonSuperTypeAccepted); var selected = selector.SelectType(new[] { ContentMediaType.Xml, ContentMediaType.Json }); Assert.Equal(ContentMediaType.Xml, selected); }
public void Single_media_type_matches() { var specificTypeAccepted = "application/json"; var selector = new ResponseMediaTypeSelector(specificTypeAccepted); var selected = selector.SelectType(new[] { ContentMediaType.Json }); Assert.Equal(ContentMediaType.Json, selected); }
public void Wild_card_media_type_matches() { var xmlAndJsonSuperTypeAccepted = "application/*"; var selector = new ResponseMediaTypeSelector(xmlAndJsonSuperTypeAccepted); var selected = selector.SelectType(new[] { ContentMediaType.Json }); Assert.Equal(ContentMediaType.Json, selected); }
public Response ResponseFrom(Request request, MediaTypeMapper mapper) { var acceptedMediaTypes = request.HeaderValueOr(RequestHeader.Accept, DefaultMediaType.ToString()); var responseMediaTypeSelector = new ResponseMediaTypeSelector(acceptedMediaTypes); var responseContentMediaType = responseMediaTypeSelector.SelectType(mapper.MappedMediaTypes); var bodyContent = mapper.From(_entity, responseContentMediaType); var body = Body.From(bodyContent); _headers.Add(ResponseHeader.Of(ResponseHeader.ContentType, responseContentMediaType.ToString())); return(Response.Of(_version, _status, _headers, body)); }