コード例 #1
0
ファイル: Startup.cs プロジェクト: DIPSASA/RestClient
 public void Configuration(IAppBuilder app)
 {
     var httpConfiguration = new HttpConfiguration();
     httpConfiguration.Formatters.Add(new BsonMediaTypeFormatter());
     var defaultNegotiator = new DefaultContentNegotiator(excludeMatchOnTypeOnly: true);
     httpConfiguration.Services.Replace(typeof(IContentNegotiator), defaultNegotiator);
     httpConfiguration.MapHttpAttributeRoutes();
     app.UseWebApi(httpConfiguration);
 }
コード例 #2
0
 public CustomContentNegotiator(Func<ContentNegotiatorContext, ContentNegotiationResult> action)
 {
     if (action == null)
     {
         throw new ArgumentNullException(nameof(action));
     }
     _action = action;
     _defaultContentNegotiator = new DefaultContentNegotiator();
 }
コード例 #3
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var config = new HttpConfiguration();
            var negotiator = new DefaultContentNegotiator(excludeMatchOnTypeOnly: true);
            config.Services.Replace(typeof(IContentNegotiator), negotiator);

            config.MapHttpAttributeRoutes();

            appBuilder.UseWebApi(config);
        }
コード例 #4
0
        public static void WhenAcceptHeaderValuesHaveQualityThenNegotiatedMediaTypeMatchesHigherQuality(string mediaType1, double quality1, string mediaType2, double quality2, string expected)
        {
            var actual = new DefaultContentNegotiator().Negotiate(
                new[] { "text/xml", "text/json" },
                new[]
                {
                    new MediaTypeWithQualityHeaderValue(mediaType1, quality1),
                    new MediaTypeWithQualityHeaderValue(mediaType2, quality2)
                });

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
ファイル: WebApiConfig.cs プロジェクト: nebtrx/roz
        public static void Register(HttpConfiguration config)
        {
            // responsible for returning the 406 when impossible to find a format for the Accept header
            DefaultContentNegotiator negotiator = new DefaultContentNegotiator(true);
            config.Services.Replace(typeof(IContentNegotiator), negotiator);

            //var xml = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
            //xml.UseXmlSerializer = true;

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            
            config.Filters.Add((IFilter)DependencyResolver.Current.GetService(typeof(HttpWebApiResponseFilter)));

            // TODO: Fix dependency resolution
            //config.Filters.Add(new DataContextApiFilter());
            config.Filters.Add((IFilter)DependencyResolver.Current.GetService(typeof(DataContextApiFilter)));
        }
コード例 #6
0
        public static void WhenAcceptHeaderStringHasQualityThenNegotiatedMediaTypeMatchesHigherQuality(string acceptHeader, string expected)
        {
            var actual = new DefaultContentNegotiator().Negotiate(new[] { "text/xml", "text/json" }, acceptHeader);

            Assert.AreEqual(expected, actual);
        }
コード例 #7
0
        public static void WhenAcceptHeaderIsMediaTypeThenNegotiatedMediaTypeMatches(string expected)
        {
            var actual = new DefaultContentNegotiator().Negotiate(new[] { "text/xml", "text/json" }, new[] { expected });

            Assert.AreEqual(expected, actual);
        }