Exemple #1
0
        public void EntityItemTypeIsSameAsItemType()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.EntityItemType.Should().BeSameAs(entityCollectionCastNode.ItemType);
        }
Exemple #2
0
 public void EntityReferenceForKeyShouldWork()
 {
     this.testSubject.ParsePath(new[] { "People(1)", "MyDog", "$ref" })
     .Last().ShouldBeNavigationPropertyLinkSegment(HardCodedTestModel.GetPersonMyDogNavProp());
 }
Exemple #3
0
        public void ActionShouldWork()
        {
            IList <ODataPathSegment> path = this.testSubject.ParsePath(new[] { "Dogs(1)", "Fully.Qualified.Namespace.Walk" });

            path[2].ShouldBeOperationSegment(HardCodedTestModel.GetDogWalkAction());
        }
Exemple #4
0
 public ExpandBinderTests()
 {
     this.binderForPerson  = new SelectExpandBinder(this.V4configuration, new ODataPathInfo(HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet()));
     this.binderForAddress = new SelectExpandBinder(this.V4configuration, new ODataPathInfo(HardCodedTestModel.GetAddressType(), null));
 }
Exemple #5
0
 public void TopLevelEntityTypeIsSetCorrectly()
 {
     this.binderForPerson.EdmType.Should().Be(HardCodedTestModel.GetPersonType());
 }
Exemple #6
0
        public void NonNavigationPropertyThrowsUsefulErrorIfKnobIsNotFlipped()
        {
            ExpandToken expandToken = new ExpandToken(new ExpandTermToken[] { new ExpandTermToken(new NonSystemToken("Shoe", null, null)) });
            Action      bind        = () => this.binderForPerson.Bind(BuildUnifiedSelectExpandToken(expandToken));

            bind.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpandItemBinder_PropertyIsNotANavigationPropertyOrComplexProperty("Shoe", HardCodedTestModel.GetPersonType().FullName()));
        }
Exemple #7
0
        public void SelectedAndExpandedNavPropProduceExpandedNavPropSelectionItemAndPathSelectionItem()
        {
            ExpandTermToken innerExpandTermToken    = new ExpandTermToken(new NonSystemToken("MyDog", null, null));
            ExpandToken     innerExpandToken        = new ExpandToken(new ExpandTermToken[] { innerExpandTermToken });
            ExpandTermToken topLevelExpandTermToken = new ExpandTermToken(new SystemToken(ExpressionConstants.It, /*nextToken*/ null), new SelectToken(new List <PathSegmentToken>()
            {
                new NonSystemToken("MyDog", /*namedValues*/ null, /*nextToken*/ null)
            }), innerExpandToken);
            ExpandToken topLevelExpandToken = new ExpandToken(new ExpandTermToken[] { topLevelExpandTermToken });
            var         item = this.binderForPerson.Bind(topLevelExpandToken);

            item.SelectedItems.Should().HaveCount(2);
            item.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp());
            item.SelectedItems.Last().ShouldBePathSelectionItem(new ODataPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), HardCodedTestModel.GetPeopleSet())));
        }
        public void CountQueryWithDuplicateCount()
        {
            Action test = () => HardCodedTestModel.ParseUri("Dogs?$count=true&$count=true", this.edmModel);

            test.ShouldThrow <ODataException>().WithMessage(Strings.QueryOptionUtils_QueryParameterMustBeSpecifiedOnce("$count"));
        }
        public void FilterThroughMissingPropertyShouldThrowOurException()
        {
            Action parse = () => HardCodedTestModel.ParseUri("People?$filter=Missing eq 1", this.edmModel);

            parse.ShouldThrow <ODataException>().WithMessage(Strings.MetadataBinder_PropertyNotDeclared("Fully.Qualified.Namespace.Person", "Missing"));
        }
Exemple #10
0
        public void ParseSelectExpand()
        {
            ODataUriParser parser    = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData"), new Uri("http://www.odata.com/OData/Dogs?$select=Color, MyPeople&$expand=MyPeople"));
            ODataUri       parsedUri = parser.ParseUri();

            parsedUri.SelectAndExpand.SelectedItems.First().ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
            var myPeopleExpand = parsedUri.SelectAndExpand.SelectedItems.Last().ShouldBeSelectedItemOfType <ExpandedNavigationSelectItem>().And;

            myPeopleExpand.PathToNavigationProperty.Single().ShouldBeNavigationPropertySegment(HardCodedTestModel.GetDogMyPeopleNavProp());
            var myPeopleSelectExpand = myPeopleExpand.SelectAndExpand;

            myPeopleSelectExpand.AllSelected.Should().BeTrue();
            myPeopleSelectExpand.SelectedItems.Should().BeEmpty();
        }
        public void OrderbyShouldHandleEmptyArgument()
        {
            var semanticTree = HardCodedTestModel.ParseUri("Dogs?$orderby=MyPeople/any()", this.edmModel);

            semanticTree.OrderBy.Expression.As <AnyNode>().Body.As <ConstantNode>().Value.Should().Be(true);
        }
Exemple #12
0
        public void ParseWithAllQueryOptionsWithoutAlias()
        {
            ODataUriParser parser = new ODataUriParser(HardCodedTestModel.TestModel, new Uri("http://www.odata.com/OData/"), new Uri("http://www.odata.com/OData/Dogs?$select=Color, MyPeople&$expand=MyPeople&$filter=startswith(Color, 'Blue')&$orderby=Color asc"));

            parser.ParsePath().FirstSegment.ShouldBeEntitySetSegment(HardCodedTestModel.GetDogsSet());
            var myDogSelectedItems = parser.ParseSelectAndExpand().SelectedItems.ToList();

            myDogSelectedItems.Count.Should().Be(3);
            myDogSelectedItems[1].ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
            var myPeopleExpansionSelectionItem = myDogSelectedItems[0].ShouldBeSelectedItemOfType <ExpandedNavigationSelectItem>().And;

            myPeopleExpansionSelectionItem.PathToNavigationProperty.Single().ShouldBeNavigationPropertySegment(HardCodedTestModel.GetDogMyPeopleNavProp());
            myPeopleExpansionSelectionItem.SelectAndExpand.SelectedItems.Should().BeEmpty();
            var startsWithArgs = parser.ParseFilter().Expression.ShouldBeSingleValueFunctionCallQueryNode("startswith").And.Parameters.ToList();

            startsWithArgs[0].ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
            startsWithArgs[1].ShouldBeConstantQueryNode("Blue");
            var orderby = parser.ParseOrderBy();

            orderby.Direction.Should().Be(OrderByDirection.Ascending);
            orderby.Expression.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp());
        }
Exemple #13
0
        public void KindIsEntityCollectionCastNode()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityCollectionCast);
        }
Exemple #14
0
        public void EntitySetComesFromSource()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Exemple #15
0
        public void BindLambdaTokenShouldFailForNonCollectionParent()
        {
            this.parentQueryNode = new ConstantNode(true);
            var binder   = new LambdaBinder(this.FakeBindMethod);
            var state    = this.GetBindingStateForTest(HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            var allToken = this.CreateTestAllQueryToken();

            Action bind = () => binder.BindLambdaToken(allToken, state);

            bind.ShouldThrow <ODataException>().
            WithMessage((Strings.MetadataBinder_LambdaParentMustBeCollection));
        }
        public void InvalidCastInFilterShouldFail()
        {
            Action test = () => HardCodedTestModel.ParseUri("People?$filter=Fully.Qualified.Namespace.Dog/Color eq 'White'", this.edmModel);

            test.ShouldThrow <ODataException>();
        }
Exemple #17
0
        public void SelectIsBasedOnTheCurrentLevel()
        {
            ExpandTermToken innerExpandTerm = new ExpandTermToken(new NonSystemToken("MyPeople", null, null));
            ExpandTermToken outerExpandTerm = new ExpandTermToken(new NonSystemToken("MyDog", null, null),
                                                                  new SelectToken(new List <PathSegmentToken>()
            {
                new NonSystemToken("Color", null, null)
            }),
                                                                  new ExpandToken(new ExpandTermToken[] { innerExpandTerm }));
            ExpandToken expandToken = new ExpandToken(new ExpandTermToken[] { outerExpandTerm });
            var         item        = this.binderForPerson.Bind(BuildUnifiedSelectExpandToken(expandToken));
            var         subExpand   =
                item.SelectedItems.First()
                .ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp())
                .And.SelectAndExpand;

            subExpand.AllSelected.Should().BeFalse();
            subExpand.SelectedItems.Single(x => x is ExpandedNavigationSelectItem).ShouldBeExpansionFor(HardCodedTestModel.GetDogMyPeopleNavProp())
            .And.SelectAndExpand.AllSelected.Should().BeTrue();
            subExpand.SelectedItems.Last(x => x is PathSelectItem).ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetDogColorProp())));
        }
        public void InvalidPropertyShouldFailUnderCastInFilter()
        {
            Action test = () => HardCodedTestModel.ParseUri("People?$filter=Fully.Qualified.Namespace.Person/WorkEmail eq '*****@*****.**'", this.edmModel);

            test.ShouldThrow <ODataException>();
        }
Exemple #19
0
        public void EntitySetCorrectlyPopulatedAtEachLevel()
        {
            ExpandTermToken innerExpandTerm = new ExpandTermToken(new NonSystemToken("MyPeople", null, null));
            ExpandTermToken outerExpandTerm = new ExpandTermToken(new NonSystemToken("MyDog", null, null),
                                                                  null,
                                                                  new ExpandToken(new ExpandTermToken[] { innerExpandTerm }));
            ExpandToken expandToken     = new ExpandToken(new ExpandTermToken[] { outerExpandTerm });
            var         item            = this.binderForPerson.Bind(BuildUnifiedSelectExpandToken(expandToken));
            var         myDogExpandItem = item.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp()).And;

            myDogExpandItem.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
            var myPeopleExpandItem = myDogExpandItem.SelectAndExpand.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetDogMyPeopleNavProp()).And;

            myPeopleExpandItem.NavigationSource.Should().Be(HardCodedTestModel.GetPeopleSet());
            myPeopleExpandItem.SelectAndExpand.SelectedItems.Should().BeEmpty();
        }
Exemple #20
0
        public void BindLambdaTokenShouldPassForOpenPropertyParent()
        {
            this.parentQueryNode = new CollectionOpenPropertyAccessNode(new ConstantNode(null), "SomeCollectionProperty");
            var binder   = new LambdaBinder(this.FakeBindMethod);
            var state    = this.GetBindingStateForTest(HardCodedTestModel.GetPaintingTypeReference(), HardCodedTestModel.GetPaintingsSet());
            var allToken = this.CreateTestAllQueryToken();

            Action bind = () => binder.BindLambdaToken(allToken, state);

            bind.ShouldNotThrow();
        }
Exemple #21
0
        public void CanSelectPropertyOnNonEntityType()
        {
            ExpandTermToken expandTermToken = new ExpandTermToken(new SystemToken(ExpressionConstants.It, null), new SelectToken(new List <PathSegmentToken>()
            {
                new NonSystemToken("City", null, null)
            }), null);
            ExpandToken expandToken = new ExpandToken(new ExpandTermToken[] { expandTermToken });
            var         item        = this.binderForAddress.Bind(expandToken);

            item.SelectedItems.Single().ShouldBePathSelectionItem(new ODataPath(new PropertySegment(HardCodedTestModel.GetAddressCityProperty())));
        }
Exemple #22
0
        public void BindLambdaTokenShouldFailForNonBoolExpression()
        {
            this.expressionQueryNode = new ConstantNode(0);
            var binder   = new LambdaBinder(this.FakeBindMethod);
            var state    = this.GetBindingStateForTest(HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            var allToken = this.CreateTestAnyQueryToken();

            Action bind = () => binder.BindLambdaToken(allToken, state);

            bind.ShouldThrow <ODataException>().
            WithMessage((Strings.MetadataBinder_AnyAllExpressionNotSingleValue));
        }
Exemple #23
0
        public void TopLevelEntityTypeCannotBeNull()
        {
            Action createWithNullTopLevelEntityType =
                () => new SelectExpandBinder(this.V4configuration, new ODataPathInfo(null, HardCodedTestModel.GetPeopleSet()));

            createWithNullTopLevelEntityType.ShouldThrow <Exception>(Error.ArgumentNull("topLevelEntityType").ToString());
        }
Exemple #24
0
        public void AllTokenWithNonEntityCollectionParentNonConstantExpression()
        {
            this.parentQueryNode     = new CollectionPropertyAccessNode(new ConstantNode(null), HardCodedTestModel.GetDogNicknamesProperty());
            this.expressionQueryNode = new BinaryOperatorNode(BinaryOperatorKind.LessThanOrEqual, new ConstantNode(1), new ConstantNode(5));
            var binder   = new LambdaBinder(this.FakeBindMethod);
            var state    = this.GetBindingStateForTest(HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            var allToken = this.CreateTestAllQueryToken();

            var result = binder.BindLambdaToken(allToken, state);

            result.ShouldBeAllQueryNode().And.Source.ShouldBeCollectionPropertyAccessQueryNode(HardCodedTestModel.GetDogNicknamesProperty());
            result.Body.ShouldBeBinaryOperatorNode(BinaryOperatorKind.LessThanOrEqual);
        }
Exemple #25
0
        public void MultiLevelExpandTermTokenWorks()
        {
            ExpandTermToken innerExpandTerm = new ExpandTermToken(new NonSystemToken("MyPeople", null, null));
            ExpandTermToken outerExpandTerm = new ExpandTermToken(new NonSystemToken("MyDog", null, null), null,
                                                                  new ExpandToken(new ExpandTermToken[] { innerExpandTerm }));
            ExpandToken expandToken     = new ExpandToken(new ExpandTermToken[] { outerExpandTerm });
            var         item            = this.binderForPerson.Bind(BuildUnifiedSelectExpandToken(expandToken));
            var         subSelectExpand = item.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetPersonMyDogNavProp()).And.SelectAndExpand;

            subSelectExpand.AllSelected.Should().BeTrue();
            subSelectExpand.SelectedItems.First().ShouldBeExpansionFor(HardCodedTestModel.GetDogMyPeopleNavProp())
            .And.SelectAndExpand.AllSelected.Should().BeTrue();
        }
Exemple #26
0
        public void AnyTokenWithEntityCollectionParentConstantExpression()
        {
            var binder   = new LambdaBinder(this.FakeBindMethod);
            var state    = this.GetBindingStateForTest(HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            var anyToken = this.CreateTestAnyQueryToken();

            var result = binder.BindLambdaToken(anyToken, state);

            result.ShouldBeAnyQueryNode().And.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetPeopleSet());
            result.Body.ShouldBeConstantQueryNode(true);
        }
Exemple #27
0
        public void SingletonShouldWork()
        {
            IList <ODataPathSegment> path = this.testSubject.ParsePath(new[] { "Boss" });

            path[0].ShouldBeSingletonSegment(HardCodedTestModel.GetBossSingleton());
        }
Exemple #28
0
        public void AnyTokenWithNonConstantExpressionNullParameter()
        {
            this.expressionQueryNode = new UnaryOperatorNode(UnaryOperatorKind.Negate, new ConstantNode(false));
            var binder     = new LambdaBinder(this.FakeBindMethod);
            var state      = this.GetBindingStateForTest(HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            var expression = new LiteralToken("foo");
            var parent     = new LiteralToken("bar");
            var anyToken   = new AnyToken(expression, null, parent);

            var result = binder.BindLambdaToken(anyToken, state);

            result.ShouldBeAnyQueryNode().And.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetPeopleSet());
            result.Body.ShouldBeUnaryOperatorNode(UnaryOperatorKind.Negate);
        }
        public void SourceIsSetCorrectly()
        {
            SingleResourceCastNode singleEntityCast = new SingleResourceCastNode(this.singleEntityNode, HardCodedTestModel.GetPersonType());

            Assert.Same(this.singleEntityNode, singleEntityCast.Source);
        }
Exemple #30
0
        public void ItemTypeReturnsEdmEntityTypeReference()
        {
            EntitySetNode            source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());

            entityCollectionCastNode.ItemType.Should().BeOfType <EdmEntityTypeReference>();
        }