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


C# ODataQueryOptions.AddAutoExpandProperties方法代码示例

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


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

示例1: ProcessLevelsCorrectly_WithAutoExpand

        public void ProcessLevelsCorrectly_WithAutoExpand()
        {
            // Arrange
            var model = GetAutoExpandEdmModel();
            var context = new ODataQueryContext(
                model,
                model.FindDeclaredType("System.Web.OData.TestCommon.Models.AutoExpandCustomer"));
            var request = new HttpRequestMessage(HttpMethod.Get, "http://test");
            var queryOption = new ODataQueryOptions(context, request);
            queryOption.AddAutoExpandProperties(new ODataQuerySettings());
            var selectExpand = queryOption.SelectExpand;

            // Act
            SelectExpandClause clause = selectExpand.ProcessLevels();

            // Assert
            Assert.True(clause.AllSelected);
            Assert.Equal(2, clause.SelectedItems.Count());

            // Level 1 of Customer.
            var cutomer = Assert.Single(
                clause.SelectedItems.OfType<ExpandedNavigationSelectItem>().Where(
                    item => item.PathToNavigationProperty.FirstSegment is NavigationPropertySegment &&
                    ((NavigationPropertySegment)item.PathToNavigationProperty.FirstSegment).NavigationProperty.Name == "Friend")
                );
            Assert.Null(cutomer.LevelsOption);

            var clauseOfCustomer = cutomer.SelectAndExpand;
            Assert.True(clauseOfCustomer.AllSelected);
            Assert.Equal(1, clauseOfCustomer.SelectedItems.Count());

            // Order under Customer.
            var order = Assert.IsType<ExpandedNavigationSelectItem>(clauseOfCustomer.SelectedItems.Single());
            Assert.Null(order.LevelsOption);

            var clauseOfOrder = order.SelectAndExpand;
            Assert.True(clauseOfOrder.AllSelected);
            Assert.Equal(1, clauseOfOrder.SelectedItems.Count());

            // ChoiceOrder under Order.
            var choiceOrder = Assert.IsType<ExpandedNavigationSelectItem>(clauseOfOrder.SelectedItems.Single());
            Assert.Null(choiceOrder.LevelsOption);

            var clauseOfChoiceOrder = choiceOrder.SelectAndExpand;
            Assert.True(clauseOfChoiceOrder.AllSelected);
            Assert.Equal(0, clauseOfChoiceOrder.SelectedItems.Count());
        }
开发者ID:joshcomley,项目名称:WebApi,代码行数:47,代码来源:SelectExpandQueryOptionTest.cs


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