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()))); }
/// <summary> /// Normalize a SelectToken into something that can be used to trim an expand tree. /// </summary> /// <param name="treeToNormalize">The select token to normalize</param> /// <returns>Normalized SelectToken</returns> public SelectToken NormalizeSelectTree(SelectToken treeToNormalize) { PathReverser pathReverser = new PathReverser(); List<PathSegmentToken> invertedPaths = (from property in treeToNormalize.Properties select property.Accept(pathReverser)).ToList(); // to normalize a select token we just need to invert its paths, so that // we match the ordering on an ExpandToken. return new SelectToken(invertedPaths); }
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 NormalizeTreeResultsInReversedPath() { // $select=1/2/3 NonSystemToken endPath = new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null))); SelectToken selectToken = new SelectToken(new NonSystemToken[]{endPath}); SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); SelectToken normalizedToken = selectTreeNormalizer.NormalizeSelectTree(selectToken); normalizedToken.Properties.Single().ShouldBeNonSystemToken("1") .And.NextToken.ShouldBeNonSystemToken("2") .And.NextToken.ShouldBeNonSystemToken("3"); }
public static SelectToken ShouldBeSelectToken(this QueryToken token, string[] propertyNames) { Assert.NotNull(token); SelectToken selectToken = Assert.IsType <SelectToken>(token); if (propertyNames.Any()) { Assert.Equal(propertyNames.Length, selectToken.Properties.Count()); Assert.Equal(propertyNames, selectToken.Properties.Select(p => p.Identifier)); } return(selectToken); }
public void ParseNestedFilterInSelectWorks() { // Arrange & Act SelectToken selectToken = ParseSelectClause("Address($filter=true)"); // Assert Assert.NotNull(selectToken); SelectTermToken selectTermToken = Assert.Single(selectToken.SelectTerms); selectTermToken.PathToProperty.ShouldBeNonSystemToken("Address"); Assert.NotNull(selectTermToken.FilterOption); selectTermToken.FilterOption.ShouldBeLiteralQueryToken(true); }
/// <summary> /// Parses the <paramref name="select"/> and <paramref name="expand"/> clauses on the given <paramref name="elementType"/>, binding /// the text into a metadata-bound list of properties to be selected using the provided model. /// </summary> /// <param name="select">String representation of the select expression from the URI.</param> /// <param name="expand">String representation of the expand expression from the URI.</param> /// <param name="elementType">Type that the select and expand clauses are projecting.</param> /// <param name="entitySet">EntitySet that the elements being filtered are from.</param> /// <returns>A <see cref="SelectExpandClause"/> representing the metadata bound orderby expression.</returns> private SelectExpandClause ParseSelectAndExpandImplementation(string select, string expand, IEdmEntityType elementType, IEdmEntitySet entitySet) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentNotNull(this.configuration.Model, "model"); ExceptionUtils.CheckArgumentNotNull(elementType, "elementType"); ISelectExpandTermParser selectParser = SelectExpandTermParserFactory.Create(select, this.Settings); SelectToken selectToken = selectParser.ParseSelect(); ISelectExpandTermParser expandParser = SelectExpandTermParserFactory.Create(expand, this.Settings); ExpandToken expandToken = expandParser.ParseExpand(); return(SelectExpandSemanticBinder.Parse(elementType, entitySet, expandToken, selectToken, this.configuration)); }
public void FunctionCallsInSelectTreeThrows() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("substring", null, null)) }); // Act Action test = () => BinderForPerson.Bind(null, selectToken); // Arrange test.Throws <ODataException>(Strings.MetadataBinder_PropertyNotDeclared(HardCodedTestModel.GetPersonType(), "substring")); }
public void NullOrEmptyOrWhiteSpaceSelectBecomesEmptyList(string clauseToParse) { // Arrange SelectExpandParser parser = new SelectExpandParser(clauseToParse, ODataUriParserSettings.DefaultSelectExpandLimit); // Act SelectToken selectToken = parser.ParseSelect(); // Assert Assert.NotNull(selectToken.Properties); Assert.Empty(selectToken.Properties); Assert.NotNull(selectToken.SelectTerms); Assert.Empty(selectToken.SelectTerms); }
public void ExistingWildcardPreemptsAnyNewPropertiesAdded() { var expandTree = new SelectExpandClause(new Collection <SelectItem>() { new WildcardSelectItem() }, false); var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree, DefaultUriResolver, null); var selectToken = new SelectToken(new List <PathSegmentToken>() { new NonSystemToken("Name", null, null) }); binder.Bind(selectToken).SelectedItems.Single().ShouldBeWildcardSelectionItem(); }
public void MultiLevelPathAfterNavigationPropertyThrows() { // Arrange : $select=MyDog/Color SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("MyDog", null, new NonSystemToken("Color", null, null))) }); // Act Action test = () => BinderForPerson.Bind(null, selectToken); // Assert test.Throws <ODataException>(Strings.SelectBinder_MultiLevelPathInSelect); }
public void CanSelectPropertyOnNonEntityType() { // Arrange SelectToken select = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("City", null, null)) }); // Arrange SelectExpandClause item = BinderForAddress.Bind(null, select); // Assert item.SelectedItems.Single().ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetAddressCityProperty()))); }
public void SystemTokenInSelectionThrows() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("Shoe", null, new SystemToken("$value", null))) }); // Act Action test = () => BinderForPerson.Bind(null, selectToken); // Assert test.Throws <ODataException>(Strings.SelectExpandBinder_SystemTokenInSelect("$value")); }
public void InvlidIdentifierInSelectionThrows() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("Dotted.Name", null, null)) }); // Act Action test = () => BinderForPerson.Bind(null, selectToken); // Assert test.Throws <ODataException>(Strings.MetadataBinder_InvalidIdentifierInQueryOption("Dotted.Name")); }
public void CustomFunctionsThrow() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("GetCoolPeople", null, null)) }); // Act Action test = () => BinderForPerson.Bind(null, selectToken); // Assert test.Throws <ODataException>(Strings.MetadataBinder_PropertyNotDeclared(HardCodedTestModel.GetPersonType(), "GetCoolPeople")); }
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, DefaultUriResolver, null); var selectToken = new SelectToken(new List <PathSegmentToken>() { new NonSystemToken("*", null, null) }); binder.Bind(selectToken).SelectedItems.Single().ShouldBeWildcardSelectionItem(); }
/// <summary> /// Create an expand term token /// </summary> /// <param name="pathToNavProp">the nav prop for this expand term</param> /// <param name="filterOption">the filter option for this expand term</param> /// <param name="orderByOptions">the orderby options for this expand term</param> /// <param name="topOption">the top option for this expand term</param> /// <param name="skipOption">the skip option for this expand term</param> /// <param name="countQueryOption">the query count option for this expand term</param> /// <param name="levelsOption">the levels option for this expand term</param> /// <param name="searchOption">the search option for this expand term</param> /// <param name="selectOption">the select option for this expand term</param> /// <param name="expandOption">the expand option for this expand term</param> public ExpandTermToken(PathSegmentToken pathToNavProp, QueryToken filterOption, IEnumerable <OrderByToken> orderByOptions, long?topOption, long?skipOption, bool?countQueryOption, long?levelsOption, QueryToken searchOption, SelectToken selectOption, ExpandToken expandOption) { ExceptionUtils.CheckArgumentNotNull(pathToNavProp, "property"); this.pathToNavProp = pathToNavProp; this.filterOption = filterOption; this.orderByOptions = orderByOptions; this.topOption = topOption; this.skipOption = skipOption; this.countQueryOption = countQueryOption; this.levelsOption = levelsOption; this.searchOption = searchOption; this.selectOption = selectOption; this.expandOption = expandOption; }
/// <summary> /// Create an expand term token /// </summary> /// <param name="pathToNavigationProp">the nav prop for this expand term</param> /// <param name="filterOption">the filter option for this expand term</param> /// <param name="orderByOptions">the orderby options for this expand term</param> /// <param name="topOption">the top option for this expand term</param> /// <param name="skipOption">the skip option for this expand term</param> /// <param name="countQueryOption">the query count option for this expand term</param> /// <param name="levelsOption">the levels option for this expand term</param> /// <param name="searchOption">the search option for this expand term</param> /// <param name="selectOption">the select option for this expand term</param> /// <param name="expandOption">the expand option for this expand term</param> /// <param name="computeOption">the compute option for this expand term.</param> public ExpandTermToken( PathSegmentToken pathToNavigationProp, QueryToken filterOption, IEnumerable <OrderByToken> orderByOptions, long?topOption, long?skipOption, bool?countQueryOption, long?levelsOption, QueryToken searchOption, SelectToken selectOption, ExpandToken expandOption, ComputeToken computeOption) : this(pathToNavigationProp, filterOption, orderByOptions, topOption, skipOption, countQueryOption, levelsOption, searchOption, selectOption, expandOption, computeOption, null) { }
public void NewTopLevelExpandTokenReferencesDollarIt() { ExpandToken originalExpand = new ExpandToken( new List<ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/null, /*nextToken*/null), /*SelectOption*/null, /*ExpandOption*/null) }); SelectToken originalSelect = new SelectToken( new List<PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/null, /*nextToken*/null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); unifiedExpand.ExpandTerms.Single().ShouldBeExpandTermToken(ExpressionConstants.It, true); }
public void AllSelectedIsNotSetIfSelectedIsNotEmpty() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("Name", null, null)) // normal property }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); Assert.False(clause.AllSelected); }
public void ParseOrderByThisInSelectWorks(string queryString, OrderByDirection orderByDirection) { // Arrange & Act SelectToken selectToken = ParseSelectClause(queryString); // Assert Assert.NotNull(selectToken); SelectTermToken selectTermToken = Assert.Single(selectToken.SelectTerms); selectTermToken.PathToProperty.ShouldBeNonSystemToken("Emails"); Assert.NotNull(selectTermToken.OrderByOptions); OrderByToken orderBy = Assert.Single(selectTermToken.OrderByOptions); orderBy.Expression.ShouldBeRangeVariableToken("$this"); Assert.Equal(orderByDirection, orderBy.Direction); }
public void NewTopLevelExpandTokenReferencesDollarIt() { ExpandToken originalExpand = new ExpandToken( new List <ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/ null, /*nextToken*/ null), /*SelectOption*/ null, /*ExpandOption*/ null) }); SelectToken originalSelect = new SelectToken( new List <PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/ null, /*nextToken*/ null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); unifiedExpand.ExpandTerms.Single().ShouldBeExpandTermToken(ExpressionConstants.It, true); }
public void SelectClauseIsAddedAsNewTopLevelExpandToken() { ExpandToken originalExpand = new ExpandToken( new List<ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/null, /*nextToken*/null), /*SelectOption*/null, /*ExpandOption*/null) }); SelectToken originalSelect = new SelectToken( new List<PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/null, /*nextToken*/null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); unifiedExpand.ExpandTerms.Single().As<ExpandTermToken>().SelectOption.ShouldBeSelectToken(new string[] {"Name"}); }
public void OriginalExpandTokenIsUnChanged() { ExpandToken originalExpand = new ExpandToken( new List<ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/null, /*nextToken*/null), /*SelectOption*/null, /*ExpandOption*/null) }); SelectToken originalSelect = new SelectToken( new List<PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/null, /*nextToken*/null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); var subExpand = unifiedExpand.ExpandTerms.Single().As<ExpandTermToken>().ExpandOption; subExpand.ExpandTerms.Single().ShouldBeExpandTermToken("MyDog", false); }
public void ParseNestedTopAndSkipInSelectWorks() { // Arrange & Act SelectToken selectToken = ParseSelectClause("Address($top=2;$skip=4)"); // Assert Assert.NotNull(selectToken); SelectTermToken selectTermToken = Assert.Single(selectToken.SelectTerms); selectTermToken.PathToProperty.ShouldBeNonSystemToken("Address"); Assert.NotNull(selectTermToken.TopOption); Assert.Equal(2, selectTermToken.TopOption); Assert.NotNull(selectTermToken.SkipOption); Assert.Equal(4, selectTermToken.SkipOption); }
public void NestedSkipWithValidExpression() { SelectToken select = ParseSelectToken("FavoriteColors($skip=5)"); SelectExpandClause clause = BinderForPerson.Bind(expandToken: null, selectToken: select); Assert.NotNull(clause); Assert.NotNull(clause.SelectedItems); // FavoriteColors SelectItem selectItem = Assert.Single(clause.SelectedItems); PathSelectItem subPathSelect = Assert.IsType <PathSelectItem>(selectItem); Assert.NotNull(subPathSelect.SkipOption); Assert.Equal(5, subPathSelect.SkipOption.Value); }
public void NormalizeTreeWorksForMultipleTerms() { // $select=1/2/3,4/5/6 NonSystemToken endPath = new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null))); NonSystemToken endPath1 = new NonSystemToken("6", null, new NonSystemToken("5", null, new NonSystemToken("4", null, null))); SelectToken selectToken = new SelectToken(new NonSystemToken[] { endPath, endPath1 }); SelectToken normalizedToken = SelectTreeNormalizer.NormalizeSelectTree(selectToken); List <PathSegmentToken> tokens = normalizedToken.Properties.ToList(); tokens.Should().HaveCount(2); tokens.ElementAt(0).ShouldBeNonSystemToken("1") .NextToken.ShouldBeNonSystemToken("2") .NextToken.ShouldBeNonSystemToken("3"); tokens.ElementAt(1).ShouldBeNonSystemToken("4") .NextToken.ShouldBeNonSystemToken("5") .NextToken.ShouldBeNonSystemToken("6"); }
public void SelectSetCorrectly() { SelectToken select = new SelectToken(new PathSegmentToken[] { new NonSystemToken("1", null, null) }); ExpandTermToken expandTerm = new ExpandTermToken(new NonSystemToken("stuff", null, null), null /*filterOption*/, null /*orderByOption*/, null /*topOption*/, null /*skipOption*/, null /*countQueryOption*/, null /*levelsOption*/, null /*searchOption*/, select, null /*expandOption*/); expandTerm.SelectOption.Properties.Count().Should().Be(1); expandTerm.SelectOption.Properties.ElementAt(0).ShouldBeNonSystemToken("1"); }
public void SelectClauseIsAddedAsNewTopLevelExpandToken() { ExpandToken originalExpand = new ExpandToken( new List <ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/ null, /*nextToken*/ null), /*SelectOption*/ null, /*ExpandOption*/ null) }); SelectToken originalSelect = new SelectToken( new List <PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/ null, /*nextToken*/ null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); unifiedExpand.ExpandTerms.Single().As <ExpandTermToken>().SelectOption.ShouldBeSelectToken(new string[] { "Name" }); }
public void OriginalExpandTokenIsUnChanged() { ExpandToken originalExpand = new ExpandToken( new List <ExpandTermToken>() { new ExpandTermToken(new NonSystemToken("MyDog", /*namedValues*/ null, /*nextToken*/ null), /*SelectOption*/ null, /*ExpandOption*/ null) }); SelectToken originalSelect = new SelectToken( new List <PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/ null, /*nextToken*/ null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); var subExpand = unifiedExpand.ExpandTerms.Single().As <ExpandTermToken>().ExpandOption; subExpand.ExpandTerms.Single().ShouldBeExpandTermToken("MyDog", false); }
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, DefaultUriResolver, null); var selectToken = new SelectToken(new List <PathSegmentToken>()); var result = binder.Bind(selectToken); result.AllSelected.Should().BeTrue(); result.SelectedItems.Single().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp()) .SelectAndExpand.AllSelected.Should().BeTrue(); }
public void NormalizeTreeWorksForMultipleTerms() { // $select=1/2/3,4/5/6 NonSystemToken endPath = new NonSystemToken("3", null, new NonSystemToken("2", null, new NonSystemToken("1", null, null))); NonSystemToken endPath1 = new NonSystemToken("6", null, new NonSystemToken("5", null, new NonSystemToken("4", null, null))); SelectToken selectToken = new SelectToken(new NonSystemToken[]{endPath, endPath1}); SelectTreeNormalizer selectTreeNormalizer = new SelectTreeNormalizer(); SelectToken normalizedToken = selectTreeNormalizer.NormalizeSelectTree(selectToken); List<PathSegmentToken> tokens = normalizedToken.Properties.ToList(); tokens.Should().HaveCount(2); tokens.ElementAt(0).ShouldBeNonSystemToken("1") .And.NextToken.ShouldBeNonSystemToken("2") .And.NextToken.ShouldBeNonSystemToken("3"); tokens.ElementAt(1).ShouldBeNonSystemToken("4") .And.NextToken.ShouldBeNonSystemToken("5") .And.NextToken.ShouldBeNonSystemToken("6"); }
public void ParseNestedOrderByAndSearchInSelectWorks() { // Arrange & Act SelectToken selectToken = ParseSelectClause("Address($orderby=abc;$search=xyz)"); // Assert Assert.NotNull(selectToken); SelectTermToken selectTermToken = Assert.Single(selectToken.SelectTerms); selectTermToken.PathToProperty.ShouldBeNonSystemToken("Address"); Assert.NotNull(selectTermToken.OrderByOptions); OrderByToken orderBy = Assert.Single(selectTermToken.OrderByOptions); orderBy.Expression.ShouldBeEndPathToken("abc"); Assert.NotNull(selectTermToken.SearchOption); selectTermToken.SearchOption.ShouldBeStringLiteralToken("xyz"); }
public void WildcardSelectionItemPreemptsStructuralProperties() { // Arrange : $select=* SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("*", null, null)) }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); Assert.False(clause.AllSelected); SelectItem selectItem = Assert.Single(clause.SelectedItems); selectItem.ShouldBeWildcardSelectionItem(); }
public void NavigationPropertyEndPathResultsInNavPropLinkSelectionItem() { // Arrange: $select=MyDog SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("MyDog", null, null)) }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); Assert.False(clause.AllSelected); SelectItem selectItem = Assert.Single(clause.SelectedItems); selectItem.ShouldBePathSelectionItem(new ODataPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null))); }
public void NonSystemTokenTranslatedToSelectionItem() { // Arrange: $select=Shoe SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("Shoe", null, null)) }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); Assert.False(clause.AllSelected); SelectItem selectItem = Assert.Single(clause.SelectedItems); selectItem.ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetPersonShoeProp()))); }
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, DefaultUriResolver, null); 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 ExistingWildcardPreemptsAnyNewPropertiesAdded() { // Arrange SelectToken selectToken = new SelectToken(new SelectTermToken[] { new SelectTermToken(new NonSystemToken("*", null, null)), // * new SelectTermToken(new NonSystemToken("Name", null, null)) // normal property }); // Act SelectExpandClause clause = BinderForPerson.Bind(null, selectToken); // Assert Assert.NotNull(clause); SelectItem selectItem = Assert.Single(clause.SelectedItems); selectItem.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); }
/// <summary> /// Add semantic meaning to a Select or Expand Token /// </summary> /// <param name="elementType">the top level entity type.</param> /// <param name="navigationSource">the top level navigation source</param> /// <param name="expandToken">the syntactically parsed expand token</param> /// <param name="selectToken">the syntactically parsed select token</param> /// <param name="configuration">The configuration to use for parsing.</param> /// <returns>A select expand clause bound to metadata.</returns> public SelectExpandClause Bind( IEdmStructuredType elementType, IEdmNavigationSource navigationSource, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration) { ExpandToken unifiedSelectExpandToken = SelectExpandSyntacticUnifier.Combine(expandToken, selectToken); ExpandTreeNormalizer expandTreeNormalizer = new ExpandTreeNormalizer(); ExpandToken normalizedSelectExpandToken = expandTreeNormalizer.NormalizeExpandTree(unifiedSelectExpandToken); SelectExpandBinder selectExpandBinder = new SelectExpandBinder(configuration, elementType, navigationSource); SelectExpandClause clause = selectExpandBinder.Bind(normalizedSelectExpandToken); SelectExpandClauseFinisher.AddExplicitNavPropLinksWhereNecessary(clause); new ExpandDepthAndCountValidator(configuration.Settings.MaximumExpansionDepth, configuration.Settings.MaximumExpansionCount).Validate(clause); return clause; }
/// <summary> /// Parse the raw select and expand strings into Abstract Syntax Trees /// </summary> /// <param name="selectClause">The raw select string</param> /// <param name="expandClause">the raw expand string</param> /// <param name="configuration">Configuration parameters</param> /// <param name="expandTree">the resulting expand AST</param> /// <param name="selectTree">the resulting select AST</param> public static void Parse( string selectClause, string expandClause, ODataUriParserConfiguration configuration, out ExpandToken expandTree, out SelectToken selectTree) { SelectExpandParser selectParser = new SelectExpandParser(selectClause, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveBuiltinIdentifier) { MaxPathDepth = configuration.Settings.PathLimit }; selectTree = selectParser.ParseSelect(); SelectExpandParser expandParser = new SelectExpandParser(expandClause, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveBuiltinIdentifier) { MaxPathDepth = configuration.Settings.PathLimit, MaxFilterDepth = configuration.Settings.FilterLimit, MaxOrderByDepth = configuration.Settings.OrderByLimit, MaxSearchDepth = configuration.Settings.SearchLimit }; expandTree = expandParser.ParseExpand(); }
/// <summary> /// Visits the top level select token /// </summary> /// <param name="tokenIn">the select token to visit</param> /// <returns>A new SelectExpandClause decorated with the information from the selectToken</returns> public SelectExpandClause Bind(SelectToken tokenIn) { if (tokenIn == null || !tokenIn.Properties.Any()) { // if there are no properties selected for this level, then by default we select // all properties (including nav prop links, functions, actions, and structural properties) this.visitor.DecoratedExpandClause.SetAllSelected(true); } else { // if there are properties selected for this level, then we return only // those specific properties in the payload, so clear the all selected flag // for this level. this.visitor.DecoratedExpandClause.SetAllSelected(false); foreach (PathSegmentToken property in tokenIn.Properties) { property.Accept(this.visitor); } } return this.visitor.DecoratedExpandClause; }
/// <summary> /// Parse the raw select and expand strings into Abstract Syntax Trees /// </summary> /// <param name="selectClause">the raw select string</param> /// <param name="expandClause">the raw expand string</param> /// <param name="parentEntityType">the parent entity type for expand option</param> /// <param name="configuration">the OData URI parser configuration</param> /// <param name="expandTree">the resulting expand AST</param> /// <param name="selectTree">the resulting select AST</param> public static void Parse( string selectClause, string expandClause, IEdmStructuredType parentEntityType, ODataUriParserConfiguration configuration, out ExpandToken expandTree, out SelectToken selectTree) { SelectExpandParser selectParser = new SelectExpandParser(selectClause, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier) { MaxPathDepth = configuration.Settings.PathLimit }; selectTree = selectParser.ParseSelect(); SelectExpandParser expandParser = new SelectExpandParser(configuration.Resolver, expandClause, parentEntityType, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier) { MaxPathDepth = configuration.Settings.PathLimit, MaxFilterDepth = configuration.Settings.FilterLimit, MaxOrderByDepth = configuration.Settings.OrderByLimit, MaxSearchDepth = configuration.Settings.SearchLimit }; expandTree = expandParser.ParseExpand(); }
private static void VerifySelectQueryTokensAreEqual(SelectToken expected, SelectToken actual, AssertionHandler assert) { VerifyPathSegmentTokensAreEqual(expected.Properties, actual.Properties, assert); }
/// <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 NullOriginalExpandTokenIsReflectedInNewTopLevelExpandToken() { ExpandToken originalExpand = null; SelectToken originalSelect = new SelectToken( new List<PathSegmentToken>() { new NonSystemToken("Name", /*namedValues*/null, /*nextToken*/null) }); ExpandToken unifiedExpand = SelectExpandSyntacticUnifier.Combine(originalExpand, originalSelect); unifiedExpand.ExpandTerms.Single().As<ExpandTermToken>().ExpandOption.Should().BeNull(); }
/// <summary> /// Combine a top level select and expand token /// </summary> /// <param name="expand">the original expand token</param> /// <param name="select">the original select token</param> /// <returns>A new ExpandToken with the original select token embedded within a new top level expand token.</returns> public static ExpandToken Combine(ExpandToken expand, SelectToken select) { // build a new top level expand token embedding the top level select token. ExpandTermToken newTopLevelExpandTerm = new ExpandTermToken(new SystemToken(ExpressionConstants.It, null), select, expand); return new ExpandToken(new List<ExpandTermToken>() { newTopLevelExpandTerm }); }
/// <summary> /// Get rid of duplicate selected item in SelectToken /// </summary> /// <param name="selectToken">Select token to be dealt with</param> /// <returns>A new select term containing each of the </returns> private static SelectToken RemoveDuplicateSelect(SelectToken selectToken) { return selectToken != null ? new SelectToken(selectToken.Properties.Distinct(new PathSegmentTokenEqualityComparer())) : null; }
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 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 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 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 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 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); }
public void SelectSetCorrectly() { SelectToken select = new SelectToken(new PathSegmentToken[] { new NonSystemToken("1", null, null) }); ExpandTermToken expandTerm = new ExpandTermToken(new NonSystemToken("stuff", null, null), null /*filterOption*/, null /*orderByOption*/, null /*topOption*/, null /*skipOption*/, null /*countQueryOption*/, null /*levelsOption*/, null /*searchOption*/, select, null /*expandOption*/); expandTerm.SelectOption.Properties.Count().Should().Be(1); expandTerm.SelectOption.Properties.ElementAt(0).ShouldBeNonSystemToken("1"); }
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 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(); }
private static ExpandToken BuildUnifiedSelectExpandToken(ExpandToken expandToken, SelectToken selectToken) { return new ExpandToken( new ExpandTermToken[] { new ExpandTermToken(new NonSystemToken(ExpressionConstants.It, /*namedValues*/null, /*nextToken*/null), selectToken, expandToken) }); }