public void NonSystemTokenTranslatedToSelectionItem()
        {
            var expandTree = new SelectExpandClause(new Collection<SelectItem>(), false);
            var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
            var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("Shoe", null, null) });

            binder.Bind(selectToken).SelectedItems.Single().ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetPersonShoeProp())));
        }
 public void ExistingWildcardPreemptsAnyNewPropertiesAdded()
 {
     var expandTree = new SelectExpandClause(new Collection<SelectItem>() 
                                 {
                                     new WildcardSelectItem()
                                 }, false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("Name", null, null) });
     binder.Bind(selectToken).SelectedItems.Single().ShouldBeWildcardSelectionItem();
 }
        public void WildcardSelectionItemPreemptsStructuralProperties()
        {
            var expandTree = new SelectExpandClause(new Collection<SelectItem>() 
                                        {
                                            new PathSelectItem(new ODataSelectPath(new PropertySegment( HardCodedTestModel.GetPersonNameProp()))),
                                        }, false);
            var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
            var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("*", null, null) });

            binder.Bind(selectToken).SelectedItems.Single().ShouldBeWildcardSelectionItem();
        }
 public void WildcardDoesNotPreemptOtherSelectionItems()
 {
     ODataSelectPath coolPeoplePath = new ODataSelectPath(new OperationSegment(new IEdmOperation[] { HardCodedTestModel.GetChangeStateAction() }, null));
     ODataSelectPath stuffPath = new ODataSelectPath(new OpenPropertySegment("stuff"));
     var expandTree = new SelectExpandClause(new Collection<SelectItem>()
                                 {
                                     new PathSelectItem(coolPeoplePath),
                                     new PathSelectItem(new ODataSelectPath(new NavigationPropertySegment(HardCodedTestModel.GetPaintingOwnerNavProp(), null))),
                                     new PathSelectItem(stuffPath),
                                     new PathSelectItem(new ODataSelectPath(new PropertySegment(HardCodedTestModel.GetPaintingColorsProperty())))
                                 }, false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("*", null, null) });
     var item = binder.Bind(selectToken);
     item.SelectedItems.Should().HaveCount(4)
                .And.Contain(x => x is PathSelectItem && x.As<PathSelectItem>().SelectedPath == coolPeoplePath)
                .And.Contain(x => x is PathSelectItem && x.As<PathSelectItem>().SelectedPath == stuffPath)
                .And.Contain(x => x is PathSelectItem && x.As<PathSelectItem>().SelectedPath.LastSegment is NavigationPropertySegment && x.As<PathSelectItem>().SelectedPath.LastSegment.As<NavigationPropertySegment>().NavigationProperty.Name == HardCodedTestModel.GetPaintingOwnerNavProp().Name)
                .And.Contain(x => x is WildcardSelectItem);
 }
Exemple #5
0
        /// <summary>
        /// Bind the top level expand.
        /// </summary>
        /// <param name="tokenIn">the token to visit</param>
        /// <returns>a SelectExpand clause based on this ExpandToken</returns>
        public SelectExpandClause Bind(ExpandToken tokenIn)
        {
            ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn");

            // the top level represents $it then has only select populated..
            List <SelectItem> expandedTerms = new List <SelectItem>();

            if (tokenIn.ExpandTerms.Single().ExpandOption != null)
            {
                expandedTerms.AddRange(tokenIn.ExpandTerms.Single().ExpandOption.ExpandTerms.Select(this.GenerateExpandItem).Where(expandedNavigationSelectItem => expandedNavigationSelectItem != null));
            }

            // if there are any select items at this level then allSelected is false, otherwise it's true.
            bool isAllSelected = tokenIn.ExpandTerms.Single().SelectOption == null;
            SelectExpandClause topLevelExpand = new SelectExpandClause(expandedTerms, isAllSelected);

            if (!isAllSelected)
            {
                SelectBinder selectBinder = new SelectBinder(this.Model, this.EdmType, this.Configuration.Settings.SelectExpandLimit, topLevelExpand, this.configuration.Resolver);
                selectBinder.Bind(tokenIn.ExpandTerms.Single().SelectOption);
            }

            return(topLevelExpand);
        }
 public void AllSelectedIsNotSetIfSelectedIsNotEmpty()
 {
     var expandTree = new SelectExpandClause(new Collection<SelectItem>(), true);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>(){new NonSystemToken("Name", null, null)});
     binder.Bind(selectToken).AllSelected.Should().BeFalse();
 }
 public void AllSelectedIsSetIfSelectIsEmpty()
 {
     var expandTree = new SelectExpandClause(new Collection<SelectItem>(), false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>());
     binder.Bind(selectToken).AllSelected.Should().BeTrue();
 }
 /// <summary>
 /// Decorate an expand tree using a select token.
 /// </summary>
 /// <param name="subExpand">the already built sub expand</param>
 /// <param name="currentNavProp">the current navigation property</param>
 /// <param name="select">the select token to use</param>
 /// <returns>A new SelectExpand clause decorated with the select token.</returns>
 private SelectExpandClause DecorateExpandWithSelect(SelectExpandClause subExpand, IEdmNavigationProperty currentNavProp, SelectToken select)
 {
     SelectBinder selectBinder = new SelectBinder(this.Model, currentNavProp.ToEntityType(), this.Settings.SelectExpandLimit, subExpand, this.configuration.Resolver);
     return selectBinder.Bind(select);
 }
 public void CustomFunctionsThrow()
 {
     SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>()
                                                         { new ExpandedNavigationSelectItem(
                                                         new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)), 
                                                         HardCodedTestModel.GetPeopleSet(),
                                                         new SelectExpandClause(null, false))}, true);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>()
         {
             new NonSystemToken("GetCoolPeople", null, null)
         });
     Action bindWithFunctionInSelect = () => binder.Bind(selectToken);
     bindWithFunctionInSelect.ShouldThrow<ODataException>().WithMessage(Strings.MetadataBinder_PropertyNotDeclared(HardCodedTestModel.GetPersonType(), "GetCoolPeople"));
 }
 public void NavPropEndPathResultsInNavPropLinkSelectionItem()
 {
     SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>(), false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("MyDog", null, null) });
     var result = binder.Bind(selectToken);
     result.SelectedItems.Single().ShouldBePathSelectionItem(new ODataPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)));
 }
 public void SelectAndExpandTheSameNavPropResolvesToBothTheSelectionAndExpandionAndAllSelectedIsFalse()
 {
     SelectExpandClause expandTree = new SelectExpandClause(
                                 new Collection<SelectItem>() { new ExpandedNavigationSelectItem(
                                                                                 new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)), 
                                                                                 HardCodedTestModel.GetPeopleSet(),
                                                                                 new SelectExpandClause(new Collection<SelectItem>(), false))}, false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("MyDog", null, null) });
     var result = binder.Bind(selectToken);
     result.SelectedItems.Single(x => x is ExpandedNavigationSelectItem).ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp()).And.SelectAndExpand.AllSelected.Should().BeFalse();
     result.SelectedItems.Single(x => x is PathSelectItem).ShouldBePathSelectionItem(new ODataPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), HardCodedTestModel.GetPeopleSet())));
 }
 public void ExpandWithNoSelectionIsUnchanged()
 {
     SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>(){ new ExpandedNavigationSelectItem(
                                                                                         new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)), 
                                                                                         HardCodedTestModel.GetPeopleSet(),
                                                                                         new SelectExpandClause(new Collection<SelectItem>(), true))}, true);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>());
     var result = binder.Bind(selectToken);
     result.AllSelected.Should().BeTrue();
     result.SelectedItems.Single().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp())
           .And.SelectAndExpand.AllSelected.Should().BeTrue();
 }
 public void SelectionInStartingExpandIsOverriddenWhereNecessary()
 {
     SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>(){new ExpandedNavigationSelectItem(
                                                                                                         new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)),
                                                                                                         HardCodedTestModel.GetPeopleSet(),
                                                                                                         new SelectExpandClause(new Collection<SelectItem>(), false))}, false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("Name", null, null) });
     var result = binder.Bind(selectToken);
     result.SelectedItems.Last().ShouldBePathSelectionItem(new ODataSelectPath(new PropertySegment(HardCodedTestModel.GetPersonNameProp())));
     result.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp())
           .And.SelectAndExpand.SelectedItems.Should().BeEmpty();
 }
        public void MultiLevelPathThrows()
        {
            SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>() {new ExpandedNavigationSelectItem(
                                                                                                new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)), 
                                                                                                HardCodedTestModel.GetPeopleSet(),
                                                                                                new SelectExpandClause(new Collection<SelectItem>(), true))}, true);
            SelectBinder binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
            SelectToken selectToken = new SelectToken(new List<PathSegmentToken>() { new NonSystemToken("MyDog", null, new NonSystemToken("Color", null, null)) });

            Action bindWithMultiLevelPath = () => binder.Bind(selectToken);
            bindWithMultiLevelPath.ShouldThrow<ODataException>().WithMessage(Strings.SelectBinder_MultiLevelPathInSelect);
        }
 public void MustFindNonTypeSegmentBeforeTheEndOfTheChain()
 {
     SelectExpandClause expandTree = new SelectExpandClause(new Collection<SelectItem>(), false);
     var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree);
     var selectToken = new SelectToken(new List<PathSegmentToken>()
         {
             new NonSystemToken("Fully.Qualified.Namespace.Employee", null, null)
         });
     var selectExpand = binder.Bind(selectToken);
     selectExpand.SelectedItems.Count().Should().Be(1);
 }
Exemple #16
0
        /// <summary>
        /// Decorate an expand tree using a select token.
        /// </summary>
        /// <param name="subExpand">the already built sub expand</param>
        /// <param name="currentNavProp">the current navigation property</param>
        /// <param name="select">the select token to use</param>
        /// <returns>A new SelectExpand clause decorated with the select token.</returns>
        private SelectExpandClause DecorateExpandWithSelect(SelectExpandClause subExpand, IEdmNavigationProperty currentNavProp, SelectToken select)
        {
            SelectBinder selectBinder = new SelectBinder(this.Model, currentNavProp.ToEntityType(), this.Settings.SelectExpandLimit, subExpand, this.configuration.Resolver);

            return(selectBinder.Bind(select));
        }
Exemple #17
0
        /// <summary>
        /// Bind the top level expand.
        /// </summary>
        /// <param name="tokenIn">the token to visit</param>
        /// <returns>a SelectExpand clause based on this ExpandToken</returns>
        public SelectExpandClause Bind(ExpandToken tokenIn)
        {
            ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn");

            // the top level represents $it then has only select populated..
            List<SelectItem> expandedTerms = new List<SelectItem>();
            if (tokenIn.ExpandTerms.Single().ExpandOption != null)
            {
                expandedTerms.AddRange(tokenIn.ExpandTerms.Single().ExpandOption.ExpandTerms.Select(this.GenerateExpandItem).Where(expandedNavigationSelectItem => expandedNavigationSelectItem != null));
            }

            // if there are any select items at this level then allSelected is false, otherwise it's true.
            bool isAllSelected = tokenIn.ExpandTerms.Single().SelectOption == null;
            SelectExpandClause topLevelExpand = new SelectExpandClause(expandedTerms, isAllSelected);
            if (!isAllSelected)
            {
                SelectBinder selectBinder = new SelectBinder(this.Model, this.EdmType, this.Configuration.Settings.SelectExpandLimit, topLevelExpand, this.configuration.Resolver);
                selectBinder.Bind(tokenIn.ExpandTerms.Single().SelectOption);
            }

            return topLevelExpand;
        }