Пример #1
0
        public void Init()
        {
            this.orderbyBinder = new OrderByBinder(FakeBindMethods.BindMethodReturningASinglePrimitive);

            var implicitRangeVariable = new EntityRangeVariable(ExpressionConstants.It, HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
            this.bindingState = new BindingState(configuration) { ImplicitRangeVariable = implicitRangeVariable };
            this.bindingState.RangeVariables.Push(new BindingState(configuration) { ImplicitRangeVariable = implicitRangeVariable }.ImplicitRangeVariable);
        }
Пример #2
0
 public ApplyBinderTests()
 {
     var implicitRangeVariable = new EntityRangeVariable(ExpressionConstants.It,
         HardCodedTestModel.GetPersonTypeReference(), HardCodedTestModel.GetPeopleSet());
     this._bindingState = new BindingState(_configuration) { ImplicitRangeVariable = implicitRangeVariable };
     this._bindingState.RangeVariables.Push(
         new BindingState(_configuration) { ImplicitRangeVariable = implicitRangeVariable }.ImplicitRangeVariable);
 }
Пример #3
0
        private static void BuildFilterWithBinaryOperator()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var firstNameProp = TripPinModel.Person.FindProperty("FirstName");
            var lastNameProp = TripPinModel.Person.FindProperty("LastName");

            var topIt = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);
            var friendsNavNode = new CollectionNavigationNode(friendsProp, topItRef);
            var e0 = new EntityRangeVariable("e0", personTypeRef, friendsNavNode);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);
            var fun1 = new SingleValueFunctionCallNode(
                "startswith",
                new QueryNode[]
                {
                    new SingleValuePropertyAccessNode(e0Ref, firstNameProp),
                    new ConstantNode("var1", "'var1'")
                },
                EdmCoreModel.Instance.GetBoolean(false));

            var friendsNavNode2 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1 = new EntityRangeVariable("e1", personTypeRef, friendsNavNode2);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);
            var fun2 = new SingleValueFunctionCallNode(
                "contains",
                new QueryNode[]
                {
                    new SingleValuePropertyAccessNode(e1Ref, lastNameProp),
                    new ConstantNode("var2", "'var2'")
                },
                EdmCoreModel.Instance.GetBoolean(false));

            // Actually $it also needed, but would not be used in UriBuilder, so omit it here.
            var any2 = new AnyNode(new Collection<RangeVariable> { e1 }, e1)
            {
                Body = fun2,
                Source = friendsNavNode2
            };

            var any1 = new AnyNode(new Collection<RangeVariable> { e0 }, e0)
            {
                Body = new BinaryOperatorNode(BinaryOperatorKind.And, fun1, any2),
                Source = friendsNavNode
            };

            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter = new FilterClause(any1, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());

            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(
            // e0:startswith(e0%2FFirstName%2C'var1') and e0%2FFriends%2Fany(e1:contains(e1%2FLastName%2C'var2')))
        }
Пример #4
0
 /// <summary>
 /// Creates an <see cref="EntityRangeVariableReferenceNode"/>.
 /// </summary>
 /// <param name="name"> The name of the associated range variable (null if none)</param>
 /// <param name="rangeVariable">The actual range variable on the bind stack that this refers to</param>
 /// <exception cref="System.ArgumentNullException">Throws if the input name or rangeVariable is null.</exception>
 public EntityRangeVariableReferenceNode(string name, EntityRangeVariable rangeVariable)
 {
     ExceptionUtils.CheckArgumentNotNull(name, "name");
     ExceptionUtils.CheckArgumentNotNull(rangeVariable, "rangeVariable");
     this.name                = name;
     this.navigationSource    = rangeVariable.NavigationSource;
     this.entityTypeReference = rangeVariable.EntityTypeReference;
     this.rangeVariable       = rangeVariable;
 }
        public void Ctor_TakingOrderByClause_InitializesProperty_Property()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            IEdmProperty property = model.Customer.FindProperty("ID");
            EntityRangeVariable variable = new EntityRangeVariable("it", model.Customer.AsReference(), model.Customers);
            SingleValuePropertyAccessNode node = new SingleValuePropertyAccessNode(new EntityRangeVariableReferenceNode("it", variable), property);
            OrderByClause orderBy = new OrderByClause(thenBy: null, expression: node, direction: OrderByDirection.Ascending, rangeVariable: variable);

            // Act
            OrderByPropertyNode orderByNode = new OrderByPropertyNode(orderBy);

            // Assert
            Assert.Equal(property, orderByNode.Property);
        }
Пример #6
0
        private static void BuildOrderBy()
        {
            var productTypeRef = new EdmEntityTypeReference(V4Model.Product, false);
            var supplierProperty = (IEdmNavigationProperty)V4Model.Product.FindProperty("Supplier");
            var nameProperty = V4Model.Supplier.FindProperty("Name");

            var topIt = new EntityRangeVariable("$it", productTypeRef, V4Model.ProductsSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);
            var supplierNavNode = new SingleNavigationNode(supplierProperty, topItRef);
            var nameNode = new SingleValuePropertyAccessNode(supplierNavNode, nameProperty);

            var orderby = new OrderByClause(null, nameNode, OrderByDirection.Ascending, topIt);
            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(V4Model.ProductsSet)),
                ServiceRoot = V4Root,
                OrderBy = orderby
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/OData/OData.svc/Products?$orderby=Supplier%2FName
        }
 public void KindIsEntityRangeVariableReferenceNode()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityRangeVariableReference);
 }
 public void EntityTypeReferenceIsSameAsTypeReference()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.EntityTypeReference.Should().BeSameAs(referenceNode.TypeReference);
 }
 public void TypeReferenceIsEdmEntityTypeReference()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.TypeReference.Should().BeOfType<EdmEntityTypeReference>();
 }
 public void TypeReferenceComesFromRangeVariable()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.TypeReference.FullName().Should().Be(HardCodedTestModel.GetDogTypeReference().FullName());
 }
Пример #11
0
 public void EntityCollectionNodeIsSetCorrectly()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.EntityCollectionNode.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
 }
Пример #12
0
 /// <summary>
 /// Compares entityrangevariables.
 /// </summary>
 /// <param name="left">Left side of comparison</param>
 /// <param name="right">Right side of comparison</param>
 /// <returns>True if equal, otherwise false</returns>
 private bool Compare(EntityRangeVariable left, EntityRangeVariable right)
 {
     if (left.Name != right.Name) return false;
     if (left.TypeReference != right.TypeReference) return false;
     if (left.NavigationSource != right.NavigationSource) return false;
     if (left.EntityTypeReference != right.EntityTypeReference) return false;
     return true;
 }
Пример #13
0
 public void GenerateQueryNodeShouldWorkIfPropertyIsPrimitiveCollection()
 {
     var property = HardCodedTestModel.GetDogNicknamesProperty();
     EntityRangeVariable rangeVariable = new EntityRangeVariable("Color", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     QueryNode result = EndPathBinder.GeneratePropertyAccessQueryNode(new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable), property);
     result.ShouldBeCollectionPropertyAccessQueryNode(HardCodedTestModel.GetDogNicknamesProperty());
 }
Пример #14
0
 /// <summary>
 /// Gets a BindingState for the test to use.
 /// </summary>
 /// <param name="type">Optional type for the implicit parameter.</param>
 /// <returns></returns>
 private BindingState GetBindingStateForTest(IEdmEntityTypeReference typeReference, IEdmEntitySet type)
 {
     type.Should().NotBeNull();
     EntityCollectionNode entityCollectionNode = new EntitySetNode(type);
     var implicitParameter = new EntityRangeVariable(ExpressionConstants.It, typeReference, entityCollectionNode);
     var state = new BindingState(this.configuration) { ImplicitRangeVariable = implicitParameter };
     state.RangeVariables.Push(state.ImplicitRangeVariable);
     return state;
 }
Пример #15
0
        public void ExpandWithNestedQueryOptionsShouldWork()
        {
            var ervFilter = new EntityRangeVariable(ExpressionConstants.It, HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            var ervOrderby = new EntityRangeVariable(ExpressionConstants.It, HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            var expand =
                new ExpandedNavigationSelectItem(
                    new ODataExpandPath(new NavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp(), null)),
                    HardCodedTestModel.GetPeopleSet(),
                    null,
                    new FilterClause(
                        new BinaryOperatorNode(
                            BinaryOperatorKind.Equal,
                            new SingleValuePropertyAccessNode(new EntityRangeVariableReferenceNode("$it", ervFilter), HardCodedTestModel.GetDogColorProp()),
                            new ConstantNode("Brown", "'Brown'")),
                            ervFilter),
                    new OrderByClause(
                        null,
                        new SingleValuePropertyAccessNode(new EntityRangeVariableReferenceNode("$it", ervOrderby), HardCodedTestModel.GetDogColorProp()),
                        OrderByDirection.Ascending,
                        ervOrderby),
                    1,
                    /* skipOption */ null,
                    true,
                    new SearchClause(new SearchTermNode("termX")),
                    /* levelsOption*/ null);

            ODataUri uri = new ODataUri()
            {
                ServiceRoot = new Uri("http://gobbledygook/"),
                Path = new ODataPath(new EntitySetSegment(HardCodedTestModel.GetPeopleSet())),
                SelectAndExpand = new SelectExpandClause(new[] { expand }, true)
            };

            Uri actualUri = new ODataUriBuilder(ODataUrlConventions.Default, uri).BuildUri();
            Assert.Equal("http://gobbledygook/People?$expand=" + Uri.EscapeDataString("MyDog($filter=Color eq 'Brown';$orderby=Color;$top=1;$count=true;$search=termX)"), actualUri.OriginalString);
        }
 private string BindRangeVariable(EntityRangeVariable entityRangeVariable)
 {
     return entityRangeVariable.Name.ToString();
 }
Пример #17
0
 public void KindShouldBeEntityRangeVariable()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.Kind.Should().Be(RangeVariableKind.Entity);
 }
Пример #18
0
 public void EntityTypeReferenceReturnsEdmEntityTypeReference()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.EntityTypeReference.Should().BeOfType<EdmEntityTypeReference>();
 }
Пример #19
0
 public void TypeReferenceIsSetCorrectly()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.TypeReference.FullName().Should().Be(HardCodedTestModel.GetDogTypeReference().FullName());
 }
Пример #20
0
 public void EntitySetIsSetCorrectly()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
        public static IEnumerable<FilterTestCase> PropertyAccessTestCases(IEdmModel model)
        {
            // Accessing a primitive property on the entity type
            EntityRangeVariable customersEntityRangeVariable = new EntityRangeVariable("dummy", model.ResolveTypeReference("TestNS.Customer", false).AsEntity(), model.FindEntityContainer("BinderTestMetadata").FindEntitySet("Customers"));
            SingleValuePropertyAccessNode propertyAccessNode = new SingleValuePropertyAccessNode(new EntityRangeVariableReferenceNode(customersEntityRangeVariable.Name, customersEntityRangeVariable),
                        model.ResolveProperty("TestNS.Customer.Name"));
            yield return new FilterTestCase()
            {
                Filter = "Name eq 'Vitek'",
                ExpectedFilterCondition = new BinaryOperatorNode(BinaryOperatorKind.Equal, propertyAccessNode, new ConstantNode("Vitek"))
            };

            // Accessing a complex on entity and primitive on complex
            SingleValuePropertyAccessNode propertyAccessNode2 = new SingleValuePropertyAccessNode(
                new SingleValuePropertyAccessNode(
                    new EntityRangeVariableReferenceNode(customersEntityRangeVariable.Name, customersEntityRangeVariable),
                    model.ResolveProperty("TestNS.Customer.Address")
                    ),
                model.ResolveProperty("TestNS.Address.City")
                );
            yield return new FilterTestCase()
            {
                Filter = "Address/City ne 'Prague'",
                ExpectedFilterCondition = new BinaryOperatorNode(BinaryOperatorKind.NotEqual, propertyAccessNode2, new ConstantNode("Prague"))
            };
        }
Пример #22
0
        private static void BuildFilterWithNestedAny()
        {
            var personTypeRef = new EdmEntityTypeReference(TripPinModel.Person, false);
            var tripTypeRef = new EdmEntityTypeReference(TripPinModel.Trip, false);

            var friendsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Friends");
            var tripsProp = (IEdmNavigationProperty)TripPinModel.Person.FindProperty("Trips");
            var budgetProp = TripPinModel.Trip.FindProperty("Budget");

            var topIt = new EntityRangeVariable("$it", personTypeRef, TripPinModel.PeopleSet);
            var topItRef = new EntityRangeVariableReferenceNode("$it", topIt);

            var friendsNavNode0 = new CollectionNavigationNode(friendsProp, topItRef);
            var e0 = new EntityRangeVariable("e0", personTypeRef, friendsNavNode0);
            var e0Ref = new EntityRangeVariableReferenceNode("e0", e0);

            var friendsNavNode1 = new CollectionNavigationNode(friendsProp, e0Ref);
            var e1 = new EntityRangeVariable("e1", personTypeRef, friendsNavNode1);
            var e1Ref = new EntityRangeVariableReferenceNode("e1", e1);

            var tripNavNode = new CollectionNavigationNode(tripsProp, e1Ref);
            var e2 = new EntityRangeVariable("e2", tripTypeRef, friendsNavNode1);
            var e2Ref = new EntityRangeVariableReferenceNode("e2", e2);

            var bugetNode = new SingleValuePropertyAccessNode(e2Ref, budgetProp);

            var gt = new BinaryOperatorNode(
                BinaryOperatorKind.GreaterThan,
                bugetNode,
                new ConstantNode(1200, "1200"));

            var any2 = new AnyNode(new Collection<RangeVariable> { e2 }, e2) { Body = gt, Source = tripNavNode };
            var any1 = new AnyNode(new Collection<RangeVariable> { e1 }, e1) { Body = any2, Source = friendsNavNode1 };
            var any0 = new AnyNode(new Collection<RangeVariable> { e0 }, e0) { Body = any1, Source = friendsNavNode0 };


            var odataUri = new ODataUri
            {
                Path = new ODataPath(new EntitySetSegment(TripPinModel.PeopleSet)),
                ServiceRoot = TripPinRoot,
                Filter = new FilterClause(any0, topIt)
            };
            var builder = new ODataUriBuilder(ODataUrlConventions.Default, odataUri);
            Console.WriteLine(builder.BuildUri());
            // http://services.odata.org/V4/TripPinService/People?$filter=Friends%2Fany(e0:e0%2FFriends%2Fany(e1:e1%2FTrips%2Fany(e2:e2%2FBudget gt 1200)))
        }
 public void RangeVariableIsSetCorrectly()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.RangeVariable.ShouldBeEntityRangeVariable(HardCodedTestModel.GetDogTypeReference()).And.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
Пример #24
0
        public void GenerateQueryNodeShouldReturnQueryNode()
        {
            var property = HardCodedTestModel.GetDogColorProp();
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityRangeVariable rangeVariable = new EntityRangeVariable("Color", HardCodedTestModel.GetDogTypeReference(), entityCollectionNode);
            var result = EndPathBinder.GeneratePropertyAccessQueryNode(
                new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable),
                property);

            result.ShouldBeSingleValuePropertyAccessQueryNode(property);
        }
 public void EntitySetComesFromRangeVariable()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);
     referenceNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
 public void NameCannotBeNull()
 {
     EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     Action createWithNullName = () => new EntityRangeVariableReferenceNode(null, rangeVariable);
     createWithNullName.ShouldThrow<Exception>(Error.ArgumentNull("name").ToString());
 }
        public static IEnumerable<FilterTestCase> TopFilterExpressionTestCases(IEdmModel model)
        {
            EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dummy", model.ResolveTypeReference("TestNS.TypeWithPrimitiveProperties", false).AsEntity(), model.FindEntityContainer("BinderTestMetadata").FindEntitySet("TypesWithPrimitiveProperties"));
            yield return new FilterTestCase()
            {
                EntitySetName = "TypesWithPrimitiveProperties",
                Filter = "BoolProperty",
                ExpectedFilterCondition = new SingleValuePropertyAccessNode(
                 new EntityRangeVariableReferenceNode(entityRangeVariable.Name, entityRangeVariable),
                 model.ResolveProperty("TestNS.TypeWithPrimitiveProperties.BoolProperty")
             )
            };

            yield return new FilterTestCase()
            {
                EntitySetName = "TypesWithPrimitiveProperties",
                Filter = "NullableBoolProperty",
                ExpectedFilterCondition = new SingleValuePropertyAccessNode(
              new EntityRangeVariableReferenceNode(entityRangeVariable.Name, entityRangeVariable),
              model.ResolveProperty("TestNS.TypeWithPrimitiveProperties.NullableBoolProperty")
          )
            };
        }
Пример #28
0
        public void CreateLambdaNodeForAllTokenShouldCreateAllNode()
        {
            BindingState bindingState = new BindingState(configuration);
            EntityCollectionNode parent = new EntitySetNode(HardCodedTestModel.GetPeopleSet());
            SingleValueNode expression = new ConstantNode(true);
            RangeVariable rangeVariable = new EntityRangeVariable("bob", HardCodedTestModel.GetPersonTypeReference(), parent);
            var resultNode = NodeFactory.CreateLambdaNode(bindingState, parent, expression, rangeVariable, QueryTokenKind.All);

            var node = resultNode.ShouldBeAllQueryNode().And;
            node.Body.Should().BeSameAs(expression);
            node.Source.Should().BeSameAs(parent);
        }
Пример #29
0
 /// <summary>
 /// Writes entity range variable to string.
 /// </summary>
 /// <param name="node">Node to write to string</param>
 /// <returns>String representation of node.</returns>
 private static string ToString(EntityRangeVariable node)
 {
     return tabHelper.Prefix + "EntityRangeVariable" +
         tabHelper.Indent(() =>
             tabHelper.Prefix + "Name = " + node.Name +
             tabHelper.Prefix + "NavigationSource = " + node.NavigationSource.Name +
             tabHelper.Prefix + "TypeReference = " + node.TypeReference
     );
 }