public void select_first_with_a_wild_card() { var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", "text/html, */*"); currentMimeType .SelectFirstMatching(new[] { "text/json", "application/json" }) .ShouldBe("text/json"); currentMimeType .SelectFirstMatching(new[] { "application/json", "text/json" }) .ShouldBe("application/json"); }
public void select_first_when_one_does_match() { var currentMimeType = new CurrentMimeType("application/x-www-form-urlencoded; charset=UTF-8", "text/html, application/json, */*"); currentMimeType .SelectFirstMatching(new[] { "text/json", "application/json" }) .ShouldBe("application/json"); }
public void WriteResource(CurrentMimeType mimeTypes, T resource) { // Select the appropriate media writer // based on the mimetype and other runtime // conditions var media = _media.SelectMedia(mimeTypes, _context); if (media == null) { // If no matching media can be found, write HTTP 406 _context.Writer.WriteResponseCode(HttpStatusCode.NotAcceptable); _context.Writer.Write(MimeType.Text, "406: Not acceptable"); } else { // Write the media based on a matching media type var outputMimetype = mimeTypes.SelectFirstMatching(media.Mimetypes); media.Write(outputMimetype, _context, resource); } }