本文整理匯總了C#中Nancy.Responses.Negotiation.Negotiator.WithAllowedMediaRange方法的典型用法代碼示例。如果您正苦於以下問題:C# Negotiator.WithAllowedMediaRange方法的具體用法?C# Negotiator.WithAllowedMediaRange怎麽用?C# Negotiator.WithAllowedMediaRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Nancy.Responses.Negotiation.Negotiator
的用法示例。
在下文中一共展示了Negotiator.WithAllowedMediaRange方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Should_boost_html_priority_if_set_to_the_same_priority_as_others
public void Should_boost_html_priority_if_set_to_the_same_priority_as_others()
{
// Given
var browser = new Browser(with =>
{
with.ResponseProcessor<TestProcessor>();
with.Module(new ConfigurableNancyModule(x =>
{
x.Get("/", (parameters, module) =>
{
var context =
new NancyContext();
var negotiator =
new Negotiator(context);
negotiator.WithAllowedMediaRange("application/xml");
negotiator.WithAllowedMediaRange("text/html");
return negotiator;
});
}));
});
// When
var response = browser.Get("/", with =>
{
with.Header("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4");
with.Accept("application/xml", 0.9m);
with.Accept("text/html", 0.9m);
});
// Then
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(response.Body.AsString().Contains("text/html"), "Media type mismatch");
}
示例2: Should_ignore_stupid_browsers_that_ask_for_xml
public void Should_ignore_stupid_browsers_that_ask_for_xml()
{
// Given
var browser = new Browser(with =>
{
with.ResponseProcessor<TestProcessor>();
with.Module(new ConfigurableNancyModule(x =>
{
x.Get("/", parameters =>
{
var context =
new NancyContext { NegotiationContext = new NegotiationContext() };
var negotiator =
new Negotiator(context);
negotiator.WithAllowedMediaRange("application/xml");
negotiator.WithAllowedMediaRange("text/html");
return negotiator;
});
}));
});
// When
var response = browser.Get("/", with =>
{
with.Header("User-Agent", "Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)");
with.Accept("application/xml", 1.0m);
with.Accept("application/xhtml+xml", 1.0m);
with.Accept("*/*", 0.9m);
});
// Then
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(response.Body.AsString().Contains("text/html"), "Media type mismatch");
}