static PipelineBinder() { __methodCallBinder = new MethodInfoMethodCallBinder <PipelineBindingContext>(); __methodCallBinder.Register(new AnyBinder(), AnyBinder.GetSupportedMethods()); __methodCallBinder.Register(new AverageBinder(), AverageBinder.GetSupportedMethods()); __methodCallBinder.Register(new CountBinder(), CountBinder.GetSupportedMethods()); __methodCallBinder.Register(new DistinctBinder(), DistinctBinder.GetSupportedMethods()); __methodCallBinder.Register(new FirstBinder(), FirstBinder.GetSupportedMethods()); __methodCallBinder.Register(new GroupByBinder(), GroupByBinder.GetSupportedMethods()); __methodCallBinder.Register(new GroupByWithResultSelectorBinder(), GroupByWithResultSelectorBinder.GetSupportedMethods()); __methodCallBinder.Register(new JoinBinder(), JoinBinder.GetSupportedMethods()); __methodCallBinder.Register(new MaxBinder(), MaxBinder.GetSupportedMethods()); __methodCallBinder.Register(new MinBinder(), MinBinder.GetSupportedMethods()); __methodCallBinder.Register(new OfTypeBinder(), OfTypeBinder.GetSupportedMethods()); __methodCallBinder.Register(new OrderByBinder(), OrderByBinder.GetSupportedMethods()); __methodCallBinder.Register(new SampleBinder(), SampleBinder.GetSupportedMethods()); __methodCallBinder.Register(new SelectBinder(), SelectBinder.GetSupportedMethods()); __methodCallBinder.Register(new SelectManyBinder(), SelectManyBinder.GetSupportedMethods()); __methodCallBinder.Register(new SingleBinder(), SingleBinder.GetSupportedMethods()); __methodCallBinder.Register(new SkipBinder(), SkipBinder.GetSupportedMethods()); __methodCallBinder.Register(new StandardDeviationPopulationBinder(), StandardDeviationPopulationBinder.GetSupportedMethods()); __methodCallBinder.Register(new StandardDeviationSampleBinder(), StandardDeviationSampleBinder.GetSupportedMethods()); __methodCallBinder.Register(new SumBinder(), SumBinder.GetSupportedMethods()); __methodCallBinder.Register(new TakeBinder(), TakeBinder.GetSupportedMethods()); __methodCallBinder.Register(new ThenByBinder(), ThenByBinder.GetSupportedMethods()); __methodCallBinder.Register(new WhereBinder(), WhereBinder.GetSupportedMethods()); }
static EmbeddedPipelineBinder() { var infoBinder = new MethodInfoMethodCallBinder <EmbeddedPipelineBindingContext>(); infoBinder.Register(new AllBinder(), AllBinder.GetSupportedMethods()); infoBinder.Register(new AnyBinder(), AnyBinder.GetSupportedMethods()); infoBinder.Register(new AverageBinder(), AverageBinder.GetSupportedMethods()); infoBinder.Register(new DistinctBinder(), DistinctBinder.GetSupportedMethods()); infoBinder.Register(new ExceptBinder(), ExceptBinder.GetSupportedMethods()); infoBinder.Register(new FirstBinder(), FirstBinder.GetSupportedMethods()); infoBinder.Register(new IntersectBinder(), IntersectBinder.GetSupportedMethods()); infoBinder.Register(new LastBinder(), LastBinder.GetSupportedMethods()); infoBinder.Register(new MaxBinder(), MaxBinder.GetSupportedMethods()); infoBinder.Register(new MinBinder(), MinBinder.GetSupportedMethods()); infoBinder.Register(new SelectBinder(), SelectBinder.GetSupportedMethods()); infoBinder.Register(new SumBinder(), SumBinder.GetSupportedMethods()); infoBinder.Register(new ToArrayBinder(), ToArrayBinder.GetSupportedMethods()); infoBinder.Register(new ToHashSetBinder(), ToHashSetBinder.GetSupportedMethods()); infoBinder.Register(new ToListBinder(), ToListBinder.GetSupportedMethods()); infoBinder.Register(new UnionBinder(), UnionBinder.GetSupportedMethods()); infoBinder.Register(new WhereBinder(), WhereBinder.GetSupportedMethods()); var nameBinder = new NameBasedMethodCallBinder <EmbeddedPipelineBindingContext>(); nameBinder.Register(new ContainsBinder(), ContainsBinder.IsSupported, ContainsBinder.SupportedMethodNames); nameBinder.Register(new CountBinder(), CountBinder.IsSupported, CountBinder.SupportedMethodNames); __methodCallBinder = new CompositeMethodCallBinder <EmbeddedPipelineBindingContext>( infoBinder, nameBinder); }
/// <summary> /// Add semantic meaning to a Select or Expand Token /// </summary> /// <param name="elementType">the top level entity type.</param> /// <param name="entitySet">the top level entity set</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 static SelectExpandClause Parse( IEdmEntityType elementType, IEdmEntitySet entitySet, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration) { expandToken = ExpandTreeNormalizer.NormalizeExpandTree(expandToken); selectToken = SelectTreeNormalizer.NormalizeSelectTree(selectToken); ExpandBinder expandBinder = ExpandBinderFactory.Create(elementType, entitySet, configuration); SelectExpandClause clause = expandBinder.Bind(expandToken); SelectBinder selectedPropertyBinder = new SelectBinder(configuration.Model, elementType, configuration.Settings.SelectExpandLimit, clause); clause = selectedPropertyBinder.Bind(selectToken); var prunedTree = SelectExpandTreeFinisher.PruneSelectExpandTree(clause); prunedTree.ComputeFinalSelectedItems(); new ExpandDepthAndCountValidator(configuration.Settings.MaximumExpansionDepth, configuration.Settings.MaximumExpansionCount).Validate(prunedTree); return(prunedTree); }
public void AllSelectedIsSetIfSelectIsEmpty() { var expandTree = new SelectExpandClause(new Collection <SelectItem>(), false); var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree, DefaultUriResolver, null); var selectToken = new SelectToken(new List <PathSegmentToken>()); binder.Bind(selectToken).AllSelected.Should().BeTrue(); }
public void NonSystemTokenTranslatedToSelectionItem() { var expandTree = new SelectExpandClause(new Collection <SelectItem>(), false); var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree, DefaultUriResolver, null); 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 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 MustFindNonTypeSegmentBeforeTheEndOfTheChain() { SelectExpandClause expandTree = new SelectExpandClause(new Collection <SelectItem>(), false); var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree, DefaultUriResolver, null); 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 NavPropEndPathResultsInNavPropLinkSelectionItem() { SelectExpandClause expandTree = new SelectExpandClause(new Collection <SelectItem>(), false); var binder = new SelectBinder(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), 800, expandTree, DefaultUriResolver, null); 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 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 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(); }
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 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 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, DefaultUriResolver, null); 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 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, DefaultUriResolver, null); 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()).SelectAndExpand.AllSelected.Should().BeFalse(); result.SelectedItems.Single(x => x is PathSelectItem).ShouldBePathSelectionItem(new ODataPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), HardCodedTestModel.GetPeopleSet()))); }
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, DefaultUriResolver, null); 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()) .SelectAndExpand.SelectedItems.Should().BeEmpty(); }
static EmbeddedPipelineBinder() { var infoBinder = new MethodInfoMethodCallBinder <EmbeddedPipelineBindingContext>(); infoBinder.Register(new AggregateBinder(), AggregateBinder.GetSupportedMethods()); infoBinder.Register(new AllBinder(), AllBinder.GetSupportedMethods()); infoBinder.Register(new AnyBinder(), AnyBinder.GetSupportedMethods()); infoBinder.Register(new AsQueryableBinder(), AsQueryableBinder.GetSupportedMethods()); infoBinder.Register(new AverageBinder(), AverageBinder.GetSupportedMethods()); infoBinder.Register(new ConcatBinder(), ConcatBinder.GetSupportedMethods()); infoBinder.Register(new DefaultIfEmptyBinder(), DefaultIfEmptyBinder.GetSupportedMethods()); infoBinder.Register(new DistinctBinder(), DistinctBinder.GetSupportedMethods()); infoBinder.Register(new ExceptBinder(), ExceptBinder.GetSupportedMethods()); infoBinder.Register(new FirstBinder(), FirstBinder.GetSupportedMethods()); infoBinder.Register(new IntersectBinder(), IntersectBinder.GetSupportedMethods()); infoBinder.Register(new LastBinder(), LastBinder.GetSupportedMethods()); infoBinder.Register(new MaxBinder(), MaxBinder.GetSupportedMethods()); infoBinder.Register(new MinBinder(), MinBinder.GetSupportedMethods()); infoBinder.Register(new OfTypeBinder(), OfTypeBinder.GetSupportedMethods()); infoBinder.Register(new ReverseBinder(), ReverseBinder.GetSupportedMethods()); infoBinder.Register(new SelectBinder(), SelectBinder.GetSupportedMethods()); infoBinder.Register(new SkipBinder(), SkipBinder.GetSupportedMethods()); infoBinder.Register(new StandardDeviationBinder(), StandardDeviationBinder.GetSupportedMethods()); infoBinder.Register(new SumBinder(), SumBinder.GetSupportedMethods()); infoBinder.Register(new TakeBinder(), TakeBinder.GetSupportedMethods()); infoBinder.Register(new ToArrayBinder(), ToArrayBinder.GetSupportedMethods()); infoBinder.Register(new ToHashSetBinder(), ToHashSetBinder.GetSupportedMethods()); infoBinder.Register(new ToListBinder(), ToListBinder.GetSupportedMethods()); infoBinder.Register(new UnionBinder(), UnionBinder.GetSupportedMethods()); infoBinder.Register(new WhereBinder(), WhereBinder.GetSupportedMethods()); infoBinder.Register(new ZipBinder(), ZipBinder.GetSupportedMethods()); var nameBinder = new NameBasedMethodCallBinder <EmbeddedPipelineBindingContext>(); nameBinder.Register(new ContainsBinder(), ContainsBinder.IsSupported, ContainsBinder.SupportedMethodNames); nameBinder.Register(new CountBinder(), CountBinder.IsSupported, CountBinder.SupportedMethodNames); __methodCallBinder = new CompositeMethodCallBinder <EmbeddedPipelineBindingContext>( infoBinder, nameBinder); }
public void WildcardDoesNotPreemptOtherSelectionItems() { ODataSelectPath coolPeoplePath = new ODataSelectPath(new OperationSegment(new[] { HardCodedTestModel.GetChangeStateAction() }, null)); ODataSelectPath stuffPath = new ODataSelectPath(new DynamicPathSegment("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, DefaultUriResolver, null); 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); }