当前位置: 首页>>代码示例>>C#>>正文


C# Negotiator.WithAllowedMediaRange方法代码示例

本文整理汇总了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");
        }
开发者ID:ravindrapro,项目名称:Nancy,代码行数:37,代码来源:ContentNegotiationFixture.cs

示例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");
        }
开发者ID:uxTomas,项目名称:Nancy,代码行数:38,代码来源:ContentNegotiationFixture.cs


注:本文中的Nancy.Responses.Negotiation.Negotiator.WithAllowedMediaRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。