本文整理汇总了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");
}