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


C# HttpConfiguration.EnableOData方法代码示例

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


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

示例1: NavigationLinksGenerationConvention_GeneratesLinksWithCast_ForDerivedProperties

        public void NavigationLinksGenerationConvention_GeneratesLinksWithCast_ForDerivedProperties()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            builder.EntitySet<Vehicle>("vehicles");
            builder.EntitySet<Manufacturer>("manufacturers");

            IEdmModel model = builder.GetEdmModel();
            IEdmEntitySet vehiclesEdmEntitySet = model.EntityContainers().Single().FindEntitySet("vehicles");
            IEdmEntityType carType = model.AssertHasEntityType(typeof(Car));
            IEdmNavigationProperty carManufacturerProperty = carType.AssertHasNavigationProperty(model, "Manufacturer", typeof(CarManufacturer), isNullable: true, multiplicity: EdmMultiplicity.ZeroOrOne);

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(model);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute());

            IEntitySetLinkBuilder linkBuilder = model.GetEntitySetLinkBuilder(vehiclesEdmEntitySet);

            Uri uri = linkBuilder.BuildNavigationLink(
                new EntityInstanceContext()
                {
                    EdmModel = model,
                    EntitySet = vehiclesEdmEntitySet,
                    EntityType = carType,
                    UrlHelper = request.GetUrlHelper(),
                    PathHandler = new DefaultODataPathHandler(model),
                    EntityInstance = new Car { Model = 2009, Name = "Accord" }
                },
                carManufacturerProperty);

            Assert.Equal("http://localhost/vehicles(Model=2009,Name='Accord')/System.Web.Http.OData.Builder.TestModels.Car/Manufacturer", uri.AbsoluteUri);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:34,代码来源:NavigationLinksGenerationConventionTest.cs

示例2: GenerateActionLink_GeneratesLinkWithoutCast_IfEntitySetTypeMatchesActionEntityType

        public void GenerateActionLink_GeneratesLinkWithoutCast_IfEntitySetTypeMatchesActionEntityType()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var cars = builder.EntitySet<Car>("cars");
            var paintAction = cars.EntityType.Action("Paint");

            IEdmModel model = builder.GetEdmModel();
            var carsEdmSet = model.EntityContainers().Single().FindEntitySet("cars");

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(model);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute());

            Uri link = ActionLinkGenerationConvention.GenerateActionLink(
                new EntityInstanceContext()
                {
                    EdmModel = model,
                    EntitySet = carsEdmSet,
                    EntityType = carsEdmSet.ElementType,
                    UrlHelper = request.GetUrlHelper(),
                    PathHandler = new DefaultODataPathHandler(model),
                    EntityInstance = new Car { Model = 2009, Name = "Accord" }
                },
                paintAction);

            Assert.Equal("http://localhost/cars(Model=2009,Name='Accord')/Paint", link.AbsoluteUri);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:30,代码来源:ActionLinkGenerationConventionTest.cs

示例3: ODataRoutingTest

        public ODataRoutingTest()
        {
            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(ODataRoutingModel.GetModel());

            _server = new HttpServer(configuration);
            _client = new HttpClient(_server);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:8,代码来源:ODataRoutingTest.cs

示例4: GetSampleRequest

 private HttpRequestMessage GetSampleRequest()
 {
     HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/employees");
     HttpConfiguration config = new HttpConfiguration();
     config.EnableOData(GetSampleModel());
     request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
     request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute());
     request.Properties["MS_ODataPath"] = new DefaultODataPathHandler(_model).Parse("employees");
     return request;
 }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:10,代码来源:FeedTest.cs

示例5: ODataActionTests

        public ODataActionTests()
        {
            _configuration = new HttpConfiguration();
            _model = GetModel();
            _configuration.Formatters.Clear();
            _configuration.EnableOData(_model);

            _server = new HttpServer(_configuration);
            _client = new HttpClient(_server);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:10,代码来源:ODataActionTests.cs

示例6: PostEntry_InODataAtomFormat

        public void PostEntry_InODataAtomFormat()
        {
            var _config = new HttpConfiguration();
            _config.EnableOData(ODataTestUtil.GetEdmModel());

            using (HttpServer host = new HttpServer(_config))
            {
                var _client = new HttpClient(host);
                HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, new Uri(baseAddress + "People"));
                requestMessage.Content = new StringContent(BaselineResource.EntryTypePersonAtom, Encoding.UTF8, "application/atom+xml");
                using (HttpResponseMessage response = _client.SendAsync(requestMessage).Result)
                {
                    Assert.NotNull(response);
                    Assert.Equal(HttpStatusCode.Created, response.StatusCode);
                    Assert.Equal("application/atom+xml", response.Content.Headers.ContentType.MediaType);

                    ODataTestUtil.VerifyResponse(response.Content, BaselineResource.EntryTypePersonAtom);
                }
            }
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:20,代码来源:PartialTrustTest.cs

示例7: GenerateNavigationLink_GeneratesCorrectLink_EvenIfRouteDataPointsToADifferentController

        public void GenerateNavigationLink_GeneratesCorrectLink_EvenIfRouteDataPointsToADifferentController()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var orders = builder.AddEntitySet("Orders", builder.AddEntity(typeof(NavigationLinksGenerationConventionTest_Order)));

            IEdmModel model = builder.GetEdmModel();
            var edmEntitySet = model.EntityContainers().Single().EntitySets().Single();

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(model);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute(), new HttpRouteValueDictionary(new { controller = "Customers" }));

            Uri uri =
                NavigationLinksGenerationConvention.GenerateNavigationPropertyLink(
                new EntityInstanceContext
                {
                    EdmModel = model,
                    EntityInstance = new NavigationLinksGenerationConventionTest_Order { ID = 100 },
                    EntitySet = edmEntitySet,
                    EntityType = edmEntitySet.ElementType,
                    PathHandler = new DefaultODataPathHandler(model),
                    UrlHelper = request.GetUrlHelper()
                },
                edmEntitySet.ElementType.NavigationProperties().Single(),
                orders,
                includeCast: false);

            Assert.Equal("http://localhost/Orders(100)/Customer", uri.AbsoluteUri);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:31,代码来源:NavigationLinksGenerationConventionTest.cs

示例8: ODataFormatterTests

 public ODataFormatterTests()
 {
     _config = new HttpConfiguration();
     _config.EnableOData(ODataTestUtil.GetEdmModel());
     _serverFormatters = _config.Formatters.OfType<ODataMediaTypeFormatter>();
 }
开发者ID:jlamfers,项目名称:aspnetwebstack,代码行数:6,代码来源:ODataFormatterTests.cs

示例9: GenerateActionLink_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType

        public void GenerateActionLink_GeneratesLinkWithCast_IfEntitySetTypeDoesnotMatchActionEntityType()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var vehicles = builder.EntitySet<Vehicle>("vehicles");
            var car = builder.Entity<Car>();
            var paintAction = car.Action("Paint");

            IEdmModel model = builder.GetEdmModel();
            var vehiclesEdmSet = model.EntityContainers().Single().FindEntitySet("vehicles");
            var carEdmType = model.FindDeclaredType("System.Web.Http.OData.Builder.TestModels.Car") as IEdmEntityType;

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(model);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute());

            Uri link = ActionLinkGenerationConvention.GenerateActionLink(
                new EntityInstanceContext()
                {
                    EdmModel = model,
                    EntitySet = vehiclesEdmSet,
                    EntityType = carEdmType,
                    UrlHelper = request.GetUrlHelper(),
                    PathHandler = new DefaultODataPathHandler(model),
                    EntityInstance = new Car { Model = 2009, Name = "Accord" }
                },
                paintAction);

            Assert.Equal("http://localhost/vehicles(Model=2009,Name='Accord')/System.Web.Http.OData.Builder.TestModels.Car/Paint", link.AbsoluteUri);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:32,代码来源:ActionLinkGenerationConventionTest.cs

示例10: Apply_Doesnot_Override_UserConfiguration

        public void Apply_Doesnot_Override_UserConfiguration()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
            var vehicles = builder.EntitySet<Vehicle>("vehicles");
            var car = builder.AddEntity(typeof(Car));
            var paintAction = vehicles.EntityType.Action("Paint");
            paintAction.HasActionLink(ctxt => new Uri("http://localhost/ActionTestWorks"));

            _convention.Apply(paintAction, builder);

            IEdmModel model = builder.GetEdmModel();
            var vehiclesEdmSet = model.EntityContainers().Single().FindEntitySet("vehicles");
            var carEdmType = model.FindDeclaredType("System.Web.Http.OData.Builder.TestModels.Car") as IEdmEntityType;
            var paintEdmAction = model.GetAvailableProcedures(model.FindDeclaredType("System.Web.Http.OData.Builder.TestModels.Car") as IEdmEntityType).Single();

            HttpConfiguration configuration = new HttpConfiguration();
            configuration.EnableOData(model);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost");
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration;
            request.Properties[HttpPropertyKeys.HttpRouteDataKey] = new HttpRouteData(new HttpRoute());

            ActionLinkBuilder actionLinkBuilder = model.GetActionLinkBuilder(paintEdmAction);

            Uri link = actionLinkBuilder.BuildActionLink(new EntityInstanceContext()
            {
                EdmModel = model,
                EntitySet = vehiclesEdmSet,
                EntityType = carEdmType,
                UrlHelper = request.GetUrlHelper(),
                PathHandler = new DefaultODataPathHandler(model),
                EntityInstance = new Car { Model = 2009, Name = "Accord" }
            });
            Assert.Equal(
                "http://localhost/ActionTestWorks",
                link.AbsoluteUri);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:37,代码来源:ActionLinkGenerationConventionTest.cs


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