public void ValidateThrowInFindOperationsByBindingParameterTypeHierarchyExceptionDoesNotSurface()
        {
            var              model            = new FindOperationsByBindingParameterTypeHierarchyThrowingCatchableExceptionEdmModel();
            IEdmEntityType   entityType       = new EdmEntityType("n", "EntityType");
            ODataPathSegment foundPathSegment = null;

            SelectPathSegmentTokenBinder.TryBindAsOperation(new SystemToken("foo", null), model, entityType, out foundPathSegment).Should().BeFalse();
        }
Beispiel #2
0
        public void BindAsOperationWithWildcardInPathTokenAndBindingParameterTypeThrows()
        {
            var              model            = new FindOperationsByBindingParameterTypeHierarchyThrowingCatchableExceptionEdmModel();
            IEdmEntityType   entityType       = new EdmEntityType("n", "EntityType");
            ODataPathSegment foundPathSegment = null;

            Assert.False(SelectPathSegmentTokenBinder.TryBindAsOperation(new SystemToken("f*oo", null), model, entityType, out foundPathSegment));
        }
Beispiel #3
0
        public void ValidateNonCatchableExceptionsThrowInFindOperationsByBindingParameterTypeHierarchyExceptionAndSurfaces()
        {
            var              model            = new FindOperationsByBindingParameterTypeHierarchyThrowingNonCatchableExceptionEdmModel();
            IEdmEntityType   entityType       = new EdmEntityType("n", "EntityType");
            ODataPathSegment foundPathSegment = null;
            Action           test             = () => SelectPathSegmentTokenBinder.TryBindAsOperation(new SystemToken("foo", null), model, entityType, out foundPathSegment);

            Assert.Throws <OutOfMemoryException>(test);
        }
Beispiel #4
0
        private static ODataPathSegment BindQualifiedOperationToPerson(string identifier)
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(
                new NonSystemToken(identifier, null, null),
                HardCodedTestModel.TestModel,
                HardCodedTestModel.GetPersonType());

            return(segment);
        }
Beispiel #5
0
        private void ProcessTokenAsPath(NonSystemToken tokenIn)
        {
            Debug.Assert(tokenIn != null, "tokenIn != null");

            List <ODataPathSegment> pathSoFar        = new List <ODataPathSegment>();
            IEdmStructuredType      currentLevelType = this.edmType;

            // first, walk through all type segments in a row, converting them from tokens into segments.
            if (tokenIn.IsNamespaceOrContainerQualified())
            {
                PathSegmentToken firstNonTypeToken;
                pathSoFar.AddRange(SelectExpandPathBinder.FollowTypeSegments(tokenIn, this.model, this.maxDepth, ref currentLevelType, out firstNonTypeToken));
                Debug.Assert(firstNonTypeToken != null, "Did not get last token.");
                tokenIn = firstNonTypeToken as NonSystemToken;
                if (tokenIn == null)
                {
                    throw new ODataException(ODataErrorStrings.SelectPropertyVisitor_SystemTokenInSelect(firstNonTypeToken.Identifier));
                }
            }

            // next, create a segment for the first non-type segment in the path.
            ODataPathSegment lastSegment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(tokenIn, this.model, currentLevelType);

            // next, create an ODataPath and add the segments to it.
            if (lastSegment != null)
            {
                pathSoFar.Add(lastSegment);
            }

            ODataSelectPath selectedPath = new ODataSelectPath(pathSoFar);

            var selectionItem = new PathSelectItem(selectedPath);

            // non-navigation cases do not allow further segments in $select.
            if (tokenIn.NextToken != null)
            {
                throw new ODataException(ODataErrorStrings.SelectBinder_MultiLevelPathInSelect);
            }

            // if the selected item is a nav prop, then see if its already there before we add it.
            NavigationPropertySegment trailingNavPropSegment = selectionItem.SelectedPath.LastSegment as NavigationPropertySegment;

            if (trailingNavPropSegment != null)
            {
                if (this.expandClauseToDecorate.SelectedItems.Any(x => x is PathSelectItem &&
                                                                  ((PathSelectItem)x).SelectedPath.Equals(selectedPath)))
                {
                    return;
                }
            }

            this.expandClauseToDecorate.AddToSelectedItems(selectionItem);
        }
        public void ValidateNonCatchableExceptionsThrowInFindOperationsByBindingParameterTypeHierarchyExceptionAndSurfaces()
        {
            var              model            = new FindOperationsByBindingParameterTypeHierarchyThrowingStackOverflowEdmModel();
            IEdmEntityType   entityType       = new EdmEntityType("n", "EntityType");
            ODataPathSegment foundPathSegment = null;
            Action           test             = () => SelectPathSegmentTokenBinder.TryBindAsOperation(new SystemToken("foo", null), model, entityType, out foundPathSegment);

#if NETCOREAPP1_0
            test.ShouldThrow <Exception>();
#else
            test.ShouldThrow <StackOverflowException>();
#endif
        }
Beispiel #7
0
        public void NotWildcardAndNotNamespaceQualifiedWildcardResultsWildcardSelectItem(string identifier)
        {
            // Arrange
            SelectItem       selectItem;
            PathSegmentToken pathSegment = new NonSystemToken(identifier, null, null);

            // Act
            var result = SelectPathSegmentTokenBinder.TryBindAsWildcard(pathSegment, HardCodedTestModel.TestModel, out selectItem);

            // Assert
            Assert.False(result);
            Assert.Null(selectItem);
        }
Beispiel #8
0
        public void WithWildcardResultsWildcardSelectItem()
        {
            // Arrange
            SelectItem       selectItem;
            PathSegmentToken pathSegment = new NonSystemToken("*", null, null);

            // Act
            var result = SelectPathSegmentTokenBinder.TryBindAsWildcard(pathSegment, HardCodedTestModel.TestModel, out selectItem);

            // Assert
            Assert.True(result);
            Assert.NotNull(selectItem);
            Assert.IsType <WildcardSelectItem>(selectItem);
        }
        /// <summary>
        /// Visit a NonSystemToken
        /// </summary>
        /// <param name="tokenIn">the non sytem token to visit</param>
        public override void Visit(NonSystemToken tokenIn)
        {
            ExceptionUtils.CheckArgumentNotNull(tokenIn, "tokenIn");

            // before looking for type segments or paths, handle both of the wildcard cases.
            if (tokenIn.NextToken == null)
            {
                SelectItem newSelectItem;
                if (SelectPathSegmentTokenBinder.TryBindAsWildcard(tokenIn, this.model, out newSelectItem))
                {
                    this.expandClauseToDecorate.AddToSelectedItems(newSelectItem);
                    return;
                }
            }

            this.ProcessTokenAsPath(tokenIn);
        }
Beispiel #10
0
        public void NamespaceQualifiedWithWildcardResultsNamespaceQualifiedWildcardSelectItem()
        {
            // Arrange
            SelectItem       selectItem;
            PathSegmentToken pathSegment = new NonSystemToken("Fully.Qualified.Namespace.*", null, null);

            // Act
            var result = SelectPathSegmentTokenBinder.TryBindAsWildcard(pathSegment, HardCodedTestModel.TestModel, out selectItem);

            // Assert
            Assert.True(result);
            Assert.NotNull(selectItem);
            NamespaceQualifiedWildcardSelectItem namesapceQualifiedSelectItem = Assert.IsType <NamespaceQualifiedWildcardSelectItem>(selectItem);

            Assert.NotNull(namesapceQualifiedSelectItem);
            Assert.Equal("Fully.Qualified.Namespace", namesapceQualifiedSelectItem.Namespace);
        }
        public void SelectBindingShouldCheckForExtendedModelInterfaceAndLookupOperationsByBindingType()
        {
            IEdmEntityType          dummyBindingType   = new EdmEntityType("Fake", "Type");
            IEdmEntityTypeReference dummyTypeReference = new EdmEntityTypeReference(dummyBindingType, false);
            var function1 = new EdmFunction("Name.Space", "FakeFunction1", new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true), true, null, false);

            function1.AddParameter("bindingParameter", dummyTypeReference);
            var function2 = new EdmFunction("Name.Space", "FakeFunction1", new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int64), true), true, null, false);

            function2.AddParameter("bindingParameter", dummyTypeReference);

            var dummyOperations = new[] { function1, function2 };
            var resolver        = new DummyFunctionImportResolver
            {
                FindOperations = (bindingType) =>
                {
                    bindingType.Should().BeSameAs(dummyBindingType);
                    return(dummyOperations);
                }
            };
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Name.Space.FakeFunction1", null, null), resolver, dummyBindingType, DefaultUriResolver);

            segment.ShouldBeOperationSegment(dummyOperations /* TODO: parameters */);
        }
        private void ProcessTokenAsPath(NonSystemToken tokenIn)
        {
            Debug.Assert(tokenIn != null, "tokenIn != null");

            List <ODataPathSegment> pathSoFar        = new List <ODataPathSegment>();
            IEdmStructuredType      currentLevelType = this.edmType;

            // first, walk through all type segments in a row, converting them from tokens into segments.
            if (tokenIn.IsNamespaceOrContainerQualified())
            {
                PathSegmentToken firstNonTypeToken;
                pathSoFar.AddRange(SelectExpandPathBinder.FollowTypeSegments(tokenIn, this.model, this.maxDepth, this.resolver, ref currentLevelType, out firstNonTypeToken));
                Debug.Assert(firstNonTypeToken != null, "Did not get last token.");
                tokenIn = firstNonTypeToken as NonSystemToken;
                if (tokenIn == null)
                {
                    throw new ODataException(ODataErrorStrings.SelectPropertyVisitor_SystemTokenInSelect(firstNonTypeToken.Identifier));
                }
            }

            // next, create a segment for the first non-type segment in the path.
            ODataPathSegment lastSegment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(tokenIn, this.model, currentLevelType, resolver);

            // next, create an ODataPath and add the segments to it.
            if (lastSegment != null)
            {
                pathSoFar.Add(lastSegment);

                // try create a complex type property path.
                while (true)
                {
                    // no need to go on if the current property is not of complex type.
                    currentLevelType = lastSegment.EdmType as IEdmStructuredType;
                    if (currentLevelType == null || currentLevelType.TypeKind != EdmTypeKind.Complex)
                    {
                        break;
                    }

                    NonSystemToken nextToken = tokenIn.NextToken as NonSystemToken;
                    if (nextToken == null)
                    {
                        break;
                    }

                    // first try bind the segment as property.
                    lastSegment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(nextToken, this.model, currentLevelType, resolver);

                    // then try bind the segment as type cast.
                    if (lastSegment == null)
                    {
                        IEdmStructuredType typeFromNextToken = UriEdmHelpers.FindTypeFromModel(this.model, nextToken.Identifier, this.resolver) as IEdmStructuredType;

                        if (typeFromNextToken.IsOrInheritsFrom(currentLevelType))
                        {
                            lastSegment = new TypeSegment(typeFromNextToken, /*entitySet*/ null);
                        }
                    }

                    // type cast failed too.
                    if (lastSegment == null)
                    {
                        break;
                    }

                    // try move to and add next path segment.
                    tokenIn = nextToken;
                    pathSoFar.Add(lastSegment);
                }
            }

            ODataSelectPath selectedPath = new ODataSelectPath(pathSoFar);

            var selectionItem = new PathSelectItem(selectedPath);

            // non-navigation cases do not allow further segments in $select.
            if (tokenIn.NextToken != null)
            {
                throw new ODataException(ODataErrorStrings.SelectBinder_MultiLevelPathInSelect);
            }

            // if the selected item is a nav prop, then see if its already there before we add it.
            NavigationPropertySegment trailingNavPropSegment = selectionItem.SelectedPath.LastSegment as NavigationPropertySegment;

            if (trailingNavPropSegment != null)
            {
                if (this.expandClauseToDecorate.SelectedItems.Any(x => x is PathSelectItem &&
                                                                  ((PathSelectItem)x).SelectedPath.Equals(selectedPath)))
                {
                    return;
                }
            }

            this.expandClauseToDecorate.AddToSelectedItems(selectionItem);
        }
        public void QualifiedNameShouldTreatAsDynamicPropertyInOpenType()
        {
            var segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("A.B", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetOpenEmployeeType(), DefaultUriResolver);

            segment.ShouldBeDynamicPathSegment("A.B");
        }
        public void UnQualifiedActionNameShouldThrow()
        {
            Action visit = () => SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Walk", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetDogType(), DefaultUriResolver);

            visit.ShouldThrow <ODataException>().WithMessage(Strings.MetadataBinder_PropertyNotDeclared(HardCodedTestModel.GetDogType(), "Walk"));
        }
        public void UnboundOperationShouldIgnore()
        {
            var segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.GetPet1", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.Should().BeNull();
        }
        public void UnfoundProperyOnClosedTypeThrows()
        {
            Action visit = () => SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Missing", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            visit.ShouldThrow <ODataException>().WithMessage(Strings.MetadataBinder_PropertyNotDeclared(HardCodedTestModel.GetPersonType(), "Missing"));
        }
        public void PropertyNameResultsInStructuralPropertySelectionItem()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Shoe", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.ShouldBePropertySegment(HardCodedTestModel.GetPersonShoeProp());
        }
        public void ActionNameResultsInOperationSelectionItemWithAllMatchingOverloadsMatchingBindingType()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.Move", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetMoveOverloadForPerson());
        }
        public void FunctionNameResultsInOperationSelectionItemWithOnlyOverloadsBoundToTheGivenType()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.HasDog", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetEmployeeType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetHasDogOverloadForEmployee());
        }
        public void ActionNameResultsInOperationSelectionItem()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.Walk", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetDogType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetDogWalkAction());
        }
        public void NavPropNameResultsInNavigationPropertyLinkSelectionItem()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("MyDog", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.ShouldBeNavigationPropertySegment(HardCodedTestModel.GetPersonMyDogNavProp());
        }
        public void OperationWithQualifiedParameterTypeNamesShouldIgnore()
        {
            var segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Move2(Fully.Qualified.Namespace.Person,Edm.String)", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.Should().BeNull();
        }
        public void FunctionNameResultsInOperationSelectionItemWithAllMatchingOverloads()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.HasDog", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetAllHasDogFunctionOverloadsForPeople() /* TODO: parameters */);
        }
        public void UnqualifiedActionNameOnOpenTypeShouldBeInterpretedAsAnOpenProperty()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Restore", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType(), DefaultUriResolver);

            segment.ShouldBeDynamicPathSegment("Restore");
        }
        public void ActionNameResultsInOperationSelectionForDerivedBindingTypeItemWithAllMatchingOverloads()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.Move", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetEmployeeType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetMoveOverloadForEmployee() /* TODO: parameters */);
        }
        public void QualifiedActionNameOnOpenTypeShouldBeInterpretedAsAnOperation()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.Restore", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType(), DefaultUriResolver);

            segment.ShouldBeOperationSegment(HardCodedTestModel.GetRestoreAction());
        }
        public void OperationWithParenthesesShouldNotWork()
        {
            Action action = () => SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Move()", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), DefaultUriResolver).Should();

            action.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.MetadataBinder_PropertyNotDeclared("Fully.Qualified.Namespace.Person", "Move()"));
        }
        public void UnfoundProperyOnOpenTypeResultsInOpenPropertySelectionItem()
        {
            ODataPathSegment segment = SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(new NonSystemToken("Fully.Qualified.Namespace.Effervescence", null, null), HardCodedTestModel.TestModel, HardCodedTestModel.GetPaintingType(), DefaultUriResolver);

            segment.ShouldBeDynamicPathSegment("Fully.Qualified.Namespace.Effervescence");
        }