Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void TypeReferenceIsEdmEntityTypeReference()
        {
            EntityRangeVariable rangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            EntityRangeVariableReferenceNode referenceNode = new EntityRangeVariableReferenceNode(rangeVariable.Name, rangeVariable);

            referenceNode.TypeReference.Should().BeOfType <EdmEntityTypeReference>();
        }
Beispiel #3
0
        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());
        }
Beispiel #4
0
        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());
        }
Beispiel #5
0
        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 EntityCollectionNodeIsSetCorrectly()
        {
            EntitySetNode       entitySetNode       = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);

            entityRangeVariable.EntityCollectionNode.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
        }
Beispiel #7
0
        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());
        }
Beispiel #8
0
        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 void KindShouldBeEntityRangeVariable()
        {
            EntitySetNode       entitySetNode       = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);

            entityRangeVariable.Kind.Should().Be(RangeVariableKind.Entity);
        }
        public void EntityTypeReferenceReturnsEdmEntityTypeReference()
        {
            EntitySetNode       entitySetNode       = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);

            entityRangeVariable.EntityTypeReference.Should().BeOfType <EdmEntityTypeReference>();
        }
        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());
        }
        public void EntitySetIsSetCorrectly()
        {
            EntitySetNode       entitySetNode       = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);

            entityRangeVariable.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Beispiel #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());
        }
 /// <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
                             ));
 }
Beispiel #15
0
        public void KindShouldBeAllNode()
        {
            EntityRangeVariable        rangeVariable  = (EntityRangeVariable)NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            Collection <RangeVariable> rangeVariables = new Collection <RangeVariable>
            {
                rangeVariable
            };
            AllNode allNode = new AllNode(rangeVariables, rangeVariable);

            allNode.InternalKind.Should().Be(InternalQueryNodeKind.All);
        }
Beispiel #16
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);
        }
Beispiel #17
0
        public void TypeReferenceShouldBeBoolean()
        {
            EntityRangeVariable        rangeVariable  = (EntityRangeVariable)NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            Collection <RangeVariable> rangeVariables = new Collection <RangeVariable>
            {
                rangeVariable
            };
            AllNode allNode = new AllNode(rangeVariables, rangeVariable);

            allNode.TypeReference.FullName().Should().Be("Edm.Boolean");
        }
Beispiel #18
0
 /// <summary>
 /// Creates a RangeVariableReferenceNode for a given range variable
 /// </summary>
 /// <param name="rangeVariable">Name of the rangeVariable.</param>
 /// <returns>A new SingleValueNode (either an Entity or NonEntity RangeVariableReferenceNode.</returns>
 internal static SingleValueNode CreateRangeVariableReferenceNode(RangeVariable rangeVariable)
 {
     if (rangeVariable.Kind == RangeVariableKind.Nonentity)
     {
         return(new NonentityRangeVariableReferenceNode(rangeVariable.Name, (NonentityRangeVariable)rangeVariable));
     }
     else
     {
         EntityRangeVariable entityRangeVariable = (EntityRangeVariable)rangeVariable;
         return(new EntityRangeVariableReferenceNode(entityRangeVariable.Name, entityRangeVariable));
     }
 }
        public void CreateLambdaNodeForAnyTokenShouldCreateAnyNode()
        {
            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.Any);
            var node       = resultNode.ShouldBeAnyQueryNode().And;

            node.Body.Should().BeSameAs(expression);
            node.Source.Should().BeSameAs(parent);
        }
Beispiel #20
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 implicitRangeVariable = new EntityRangeVariable(ExpressionConstants.It, typeReference, entityCollectionNode);
            var state = new BindingState(this.configuration)
            {
                ImplicitRangeVariable = implicitRangeVariable
            };

            state.RangeVariables.Push(state.ImplicitRangeVariable);
            return(state);
        }
Beispiel #21
0
        public void RangeVariableShouldBeSetCorrectly()
        {
            EntityRangeVariable        rangeVariable  = (EntityRangeVariable)NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            Collection <RangeVariable> rangeVariables = new Collection <RangeVariable>
            {
                rangeVariable
            };
            AllNode allNode = new AllNode(rangeVariables, rangeVariable);

            allNode.CurrentRangeVariable.Name.Should().Be(ExpressionConstants.It);
            allNode.CurrentRangeVariable.Kind.Should().Be(RangeVariableKind.Entity);
            allNode.CurrentRangeVariable.TypeReference.FullName().Should().Be(HardCodedTestModel.GetDogTypeReference().FullName());
        }
Beispiel #22
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);
        }
        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);
        }
        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);
        }
        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);
        }
Beispiel #26
0
        public void RangeVariablesShouldBeSetCorrectly()
        {
            EntityRangeVariable        rangeVariable  = (EntityRangeVariable)NodeFactory.CreateImplicitRangeVariable(HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
            Collection <RangeVariable> rangeVariables = new Collection <RangeVariable>
            {
                rangeVariable
            };
            AllNode allNode = new AllNode(rangeVariables, rangeVariable);

            allNode.RangeVariables.Count.Should().Be(1);
            allNode.RangeVariables[0].Name.Should().Be(ExpressionConstants.It);
            allNode.RangeVariables[0].Kind.Should().Be(RangeVariableKind.Entity);
            EntityRangeVariable returnedRangeVariable = (EntityRangeVariable)allNode.RangeVariables[0];

            returnedRangeVariable.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
        }
Beispiel #27
0
        public void Init()
        {
            IEdmEntitySet        set = HardCodedTestModel.GetPeopleSet();
            EntityCollectionNode entityCollectionNode = new EntitySetNode(set);
            var implicitParameter = new EntityRangeVariable(ExpressionConstants.It, HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode);

            this.bindingState = new BindingState(this.configuration)
            {
                ImplicitRangeVariable = implicitParameter
            };
            this.bindingState.RangeVariables.Push(new BindingState(this.configuration)
            {
                ImplicitRangeVariable = implicitParameter
            }.ImplicitRangeVariable);
            this.dottedIdentifierBinder = new DottedIdentifierBinder(FakeBindMethods.BindMethodReturningASinglePerson, this.bindingState);
        }
Beispiel #28
0
        /// <summary>
        /// see comments for TranslateRangeVariable
        /// </summary>
        private string TranslateRangeVariable(EntityRangeVariable entityRangeVariable)
        {
            var res = entityRangeVariable.Name.ToString();

            //odata section 5.1.1.6.4, $it is a range variable indicating current entity queried against
            if (res == "$it")
            {
                return("c");
            }

            //override the range variable name if we are inside the body clause of an any node
            if (RangeVariablesNameForAnyNodeBody.Any())
            {
                return(RangeVariablesNameForAnyNodeBody.Peek());
            }
            return(res);
        }
Beispiel #29
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);
 }
Beispiel #30
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
        }
Beispiel #31
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();
 }