Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Forked from darrelmiller/gist:1989131
Created March 7, 2012 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tugberkugurlu/1993661 to your computer and use it in GitHub Desktop.
Save tugberkugurlu/1993661 to your computer and use it in GitHub Desktop.
Conneg with quality
[TestMethod]
public void ConnegTest()
{
var selector = new FormatterSelector();
var response = new HttpResponseMessage();
response.RequestMessage = new HttpRequestMessage();
var headers = response.RequestMessage.Headers;
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json",0.8));
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
var context = new FormatterContext(response, false);
var mediaType = new MediaTypeHeaderValue("text/plain");
selector.SelectWriteFormatter(typeof (String), context,new MediaTypeFormatterCollection(),out mediaType);
Assert.AreEqual("application/xml",mediaType.MediaType);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment