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


C# System.Collections.MapODataServiceRoute方法代码示例

本文整理汇总了C#中System.Collections.MapODataServiceRoute方法的典型用法代码示例。如果您正苦于以下问题:C# System.Collections.MapODataServiceRoute方法的具体用法?C# System.Collections.MapODataServiceRoute怎么用?C# System.Collections.MapODataServiceRoute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections的用法示例。


在下文中一共展示了System.Collections.MapODataServiceRoute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateConfiguration

 private static HttpConfiguration CreateConfiguration(IEdmModel model)
 {
     HttpConfiguration configuration =
         new[]
         {
             typeof(MainEntityController), typeof(PeopleController), typeof(EnumCustomersController),
             typeof(CollectionSerializerCustomersController), typeof(PresidentController)
         }.GetHttpConfiguration();
     configuration.MapODataServiceRoute(model);
     configuration.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create());
     return configuration;
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:12,代码来源:ODataFormatterTests.cs

示例2: GetEntry_UsesRouteModel_ForMultipleModels

        public void GetEntry_UsesRouteModel_ForMultipleModels()
        {
            // Model 1 only has Name, Model 2 only has Age
            ODataModelBuilder builder1 = new ODataModelBuilder();
            var personType1 = builder1.EntityType<FormatterPerson>();
            personType1.HasKey(p => p.PerId);
            personType1.Property(p => p.Name);
            builder1.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
            var model1 = builder1.GetEdmModel();

            ODataModelBuilder builder2 = new ODataModelBuilder();
            var personType2 = builder2.EntityType<FormatterPerson>();
            personType2.HasKey(p => p.PerId);
            personType2.Property(p => p.Age);
            builder2.EntitySet<FormatterPerson>("People").HasIdLink(p => new Uri("http://link/"), false);
            var model2 = builder2.GetEdmModel();

            var config = new[] { typeof(PeopleController) }.GetHttpConfiguration();
            config.MapODataServiceRoute("OData1", "v1", model1);
            config.MapODataServiceRoute("OData2", "v2", model2);

            using (HttpServer host = new HttpServer(config))
            using (HttpClient client = new HttpClient(host))
            {
                using (HttpResponseMessage response = client.GetAsync("http://localhost/v1/People(10)").Result)
                {
                    Assert.True(response.IsSuccessStatusCode);
                    JToken json = JToken.Parse(response.Content.ReadAsStringAsync().Result);

                    // Model 1 has the Name property but not the Age property
                    Assert.NotNull(json["Name"]);
                    Assert.Null(json["Age"]);
                }

                using (HttpResponseMessage response = client.GetAsync("http://localhost/v2/People(10)").Result)
                {
                    Assert.True(response.IsSuccessStatusCode);
                    JToken json = JToken.Parse(response.Content.ReadAsStringAsync().Result);

                    // Model 2 has the Age property but not the Name property
                    Assert.Null(json["Name"]);
                    Assert.NotNull(json["Age"]);
                }
            }
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:45,代码来源:ODataFormatterTests.cs

示例3: GetEnumResponse

        private HttpResponseMessage GetEnumResponse(string acceptHeader)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<EnumCustomer>("EnumCustomers");
            IEdmModel model = builder.GetEdmModel();

            HttpConfiguration configuration = new[] { typeof(EnumCustomersController) }.GetHttpConfiguration();
            configuration.MapODataServiceRoute("odata", routePrefix: null, model: model);
            HttpServer host = new HttpServer(configuration);
            HttpClient client = new HttpClient(host);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/EnumCustomers");
            request.Content = new StringContent(
                string.Format(@"{{'@odata.type':'#System.Web.OData.Formatter.EnumCustomer',
                            'ID':0,'Color':'Green, Blue','Colors':['Red','Red, Blue']}}"));
            request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
            request.Headers.Accept.ParseAdd(acceptHeader);

            HttpResponseMessage response = client.SendAsync(request).Result;
            return response;
        }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:21,代码来源:ODataFormatterTests.cs


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