Esempio n. 1
0
 public void CreateParameterNodeShouldReturnEntityParameterQueryNodeForEntityType()
 {
     var nodeToIterationOver = new EntitySetNode(HardCodedTestModel.GetPeopleSet());
     var resultNode = NodeFactory.CreateParameterNode("a", nodeToIterationOver);
     resultNode.ShouldBeEntityRangeVariable(HardCodedTestModel.GetPersonTypeReference())
         .And.EntityCollectionNode.NavigationSource.Should().Be(HardCodedTestModel.GetPeopleSet());
 }
Esempio n. 2
0
        public void KeyLookupWithNamedKeyReturnsKeyLookupQueryNode()
        {
            var collectionNode = new EntitySetNode(HardCodedTestModel.GetPeopleSet());
            var namedValues = new[] { new NamedValue("ID", new LiteralToken(123)) };

            var results = this.keyBinder.BindKeyValues(collectionNode, namedValues, model);
            results.ShouldBeKeyLookupQueryNode().And.KeyPropertyValues.Single().KeyValue.Should().Be(FakeBindMethods.KeyBinderConstantToken);
        }
Esempio n. 3
0
        public void KeyLookupWithMultipleUnnamedKeysShouldThrow()
        {
            var collectionNode = new EntitySetNode(HardCodedTestModel.GetLionSet());
            var namedValues = new[] { new NamedValue(null, new LiteralToken(123)), new NamedValue(null, new LiteralToken(456)), };

            Action bind = () => this.keyBinder.BindKeyValues(collectionNode, namedValues, model);
            bind.ShouldThrow<ODataException>().WithMessage(Strings.MetadataBinder_UnnamedKeyValueOnTypeWithMultipleKeyProperties(HardCodedTestModel.GetLionSet().EntityType().FullTypeName()));
        }
Esempio n. 4
0
        public void KeyLookupWithTwoKeysReturnsKeyLookupQueryNodeWithTwoKeyProperties()
        {
            var collectionNode = new EntitySetNode(HardCodedTestModel.GetLionSet());
            var namedValues = new[] { new NamedValue("ID1", new LiteralToken(123)), new NamedValue("ID2", new LiteralToken(456)) };

            var results = this.keyBinder.BindKeyValues(collectionNode, namedValues, model);
            results.ShouldBeKeyLookupQueryNode().And.KeyPropertyValues.Count().Should().Be(2);
        }
Esempio n. 5
0
        public void KeyLookupWithOneOfTwoKeysMissingShouldThrow()
        {
            var collectionNode = new EntitySetNode(HardCodedTestModel.GetLionSet());
            var namedValues = new[] { new NamedValue("ID1", new LiteralToken(123)) };

            Action bind = () => this.keyBinder.BindKeyValues(collectionNode, namedValues, model);
            bind.ShouldThrow<ODataException>().WithMessage(Strings.MetadataBinder_NotAllKeyPropertiesSpecifiedInKeyValues(collectionNode.ItemType.FullName()));
        }
Esempio n. 6
0
        public void EntitySetWithNoKeysShouldBeJustBeEntitySetQueryNode()
        {
            var collectionNode = new EntitySetNode(HardCodedTestModel.GetPeopleSet());
            var namedValues = new NamedValue[0];

            var results = this.keyBinder.BindKeyValues(collectionNode, namedValues, model);
            results.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetPeopleSet());
        }
 public void CanCreateFromEntitySetOrEntityCollectionNode()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     Action createWithEntityset = () => new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), HardCodedTestModel.GetDogsSet());
     Action createWithCollectionNode = () => new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     createWithEntityset.ShouldNotThrow();
     createWithCollectionNode.ShouldNotThrow();
 }
        public void ExplicitPropertyAccessShouldCreatePropertyAccessQueryNode()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("a", HardCodedTestModel.GetDogTypeReference(), entityCollectionNode));
            var result = this.propertyBinder.BindEndPath(token);

            result.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetDogColorProp()).
                And.Source.ShouldBeEntityRangeVariableReferenceNode("a");
        }
        public void ManyParametersInScopeShouldNotInterfere()
        {
            var token = new EndPathToken("Shoe", null);

            EntityCollectionNode dogsEntityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            EntityCollectionNode peopleEntityCollectionNode = new EntitySetNode(HardCodedTestModel.GetPeopleSet());

            this.bindingState.RangeVariables.Push(new EntityRangeVariable("a", HardCodedTestModel.GetDogTypeReference(), dogsEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("b", HardCodedTestModel.GetDogTypeReference(), dogsEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("c", HardCodedTestModel.GetDogTypeReference(), dogsEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("d", HardCodedTestModel.GetDogTypeReference(), dogsEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("e", HardCodedTestModel.GetDogTypeReference(), dogsEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("f", HardCodedTestModel.GetPersonTypeReference(), peopleEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("g", HardCodedTestModel.GetPersonTypeReference(), peopleEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("h", HardCodedTestModel.GetPersonTypeReference(), peopleEntityCollectionNode));
            this.bindingState.RangeVariables.Push(new EntityRangeVariable("i", HardCodedTestModel.GetPersonTypeReference(), peopleEntityCollectionNode));

            var result = this.propertyBinder.BindEndPath(token);

            result.ShouldBeSingleValuePropertyAccessQueryNode(HardCodedTestModel.GetPersonShoeProp()).
                And.Source.ShouldBeEntityRangeVariableReferenceNode(ExpressionConstants.It);
        }
 public void SourceIsSetCorrectly()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.Source.ShouldBeEntitySetQueryNode(HardCodedTestModel.GetDogsSet());
 }
 public void ItemTypeReturnsEdmEntityTypeReference()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.ItemType.Should().BeOfType<EdmEntityTypeReference>();
 }
 public void EntityTypeReferenceReturnsEdmEntityTypeReference()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.EntityTypeReference.Should().BeOfType<EdmEntityTypeReference>();
 }
 public void EntityTypeCannotBeNull()
 {
     EntityCollectionNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     Action createWithNullEntityType = () => new EntityCollectionCastNode(source, null);
     createWithNullEntityType.ShouldThrow<Exception>(Error.ArgumentNull("entityType").ToString());
 }
Esempio n. 14
0
 public void CreateParameterNodeShouldKeepParameterNameExactlyTheSame()
 {
     var nodeToIterationOver = new EntitySetNode(HardCodedTestModel.GetPeopleSet());
     var resultNode = NodeFactory.CreateParameterNode("PARAM_name!@#", nodeToIterationOver);
     resultNode.Name.Should().Be("PARAM_name!@#");
 }
Esempio n. 15
0
 public void KindIsEntitySet()
 {
     var node = new EntitySetNode(HardCodedTestModel.GetLionSet());
     node.InternalKind.Should().Be(InternalQueryNodeKind.EntitySet);
 }
Esempio n. 16
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;
 }
 public void KindIsEntityCollectionCastNode()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.InternalKind.Should().Be(InternalQueryNodeKind.EntityCollectionCast);
 }
Esempio n. 18
0
 public void EntityItemTypeIsSameAsItemType()
 {
     var node = new EntitySetNode(HardCodedTestModel.GetLionSet());
     node.EntityItemType.Should().BeSameAs(node.ItemType);
 }
 public void EntitySetIsSetCorrectly()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
Esempio n. 20
0
        public void ShouldThrowIfTypeNotOpen()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));
            Action getQueryNode = () => EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            getQueryNode.ShouldThrow<ODataException>().WithMessage(
                Strings.MetadataBinder_PropertyNotDeclared(parentNode.GetEdmTypeReference().ODataFullName(),
                                                                                    token.Identifier));

        }
Esempio n. 21
0
        public void ShouldThrowNotImplementedIfTypeIsOpen()
        {
            const string OpenPropertyName = "Style";
            var token = new EndPathToken(OpenPropertyName, new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetPaintingsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPaintingTypeReference(), entityCollectionNode));
            var propertyNode = EndPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode(OpenPropertyName);
        }
Esempio n. 22
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 EntityItemTypeIsSameAsItemType()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.EntityItemType.Should().BeSameAs(entityCollectionCastNode.ItemType);
 }
Esempio n. 24
0
 public void ItemTypeReturnsEdmEntityTypeReference()
 {
     var node = new EntitySetNode(HardCodedTestModel.GetLionSet());
     node.ItemType.ShouldBeEquivalentTo(HardCodedTestModel.GetLionTypeReference());
 }
 public void EntitySetComesFromSource()
 {
     EntitySetNode source = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityCollectionCastNode entityCollectionCastNode = new EntityCollectionCastNode(source, HardCodedTestModel.GetDogType());
     entityCollectionCastNode.NavigationSource.Should().Be(HardCodedTestModel.GetDogsSet());
 }
Esempio n. 26
0
        public void ShouldNotThrowIfTypeNotOpenButAggregateApplied()
        {
            var token = new EndPathToken("Color", new RangeVariableToken("a"));
            EntityCollectionNode entityCollectionNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
            SingleValueNode parentNode = new EntityRangeVariableReferenceNode("a", new EntityRangeVariable("a", HardCodedTestModel.GetPersonTypeReference(), entityCollectionNode));

            var state = new BindingState(this.configuration);
            state.AggregatedPropertyNames = new List<string> { "Color" };
            var metadataBinder = new MetadataBinder(state);
            var endPathBinder = new EndPathBinder(metadataBinder.Bind, state);
            var propertyNode = endPathBinder.GeneratePropertyAccessQueryForOpenType(
                token, parentNode);

            propertyNode.ShouldBeSingleValueOpenPropertyAccessQueryNode("Color");
        }
 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 KindShouldBeEntityRangeVariable()
 {
     EntitySetNode entitySetNode = new EntitySetNode(HardCodedTestModel.GetDogsSet());
     EntityRangeVariable entityRangeVariable = new EntityRangeVariable("dogs", HardCodedTestModel.GetDogTypeReference(), entitySetNode);
     entityRangeVariable.Kind.Should().Be(RangeVariableKind.Entity);
 }
Esempio n. 29
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);
        }
Esempio n. 30
0
 public void EntitySetComesFromSource()
 {
     var node = new EntitySetNode(HardCodedTestModel.GetLionSet());
     node.NavigationSource.Should().Be(HardCodedTestModel.GetLionSet());
 }