Пример #1
0
        public void SemicolonOnlyAllowedInParensInExpand()
        {
            SelectExpandParser parser = new SelectExpandParser("one;two", 3);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_InvalidCharacter(";", 3, "one;two"));
        }
Пример #2
0
        public void WhitespaceInMiddleOfSegmentShouldThrowInExpand()
        {
            SelectExpandParser parser = new SelectExpandParser("what happens here/foo", 3);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(Strings.UriSelectParser_TermIsNotValid("what happens here/foo"));
        }
Пример #3
0
        public void OpenCloseParensAfterNavPropShouldThrow()
        {
            SelectExpandParser parser = new SelectExpandParser("NavProp()", ODataUriParserSettings.DefaultSelectExpandLimit);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriParser_MissingExpandOption("NavProp"));
        }
Пример #4
0
        public void MaxRecursionDepthIsEnforcedInExpand()
        {
            SelectExpandParser parser = new SelectExpandParser("stuff/stuff/stuff/stuff", 3);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_TooDeep);
        }
Пример #5
0
        public void EmptyExpandTermShouldThrow()
        {
            SelectExpandParser parser = new SelectExpandParser("one,,two", ODataUriParserSettings.DefaultSelectExpandLimit);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionToken_IdentifierExpected("4"));
        }
Пример #6
0
        public void NestedOptionsWithExtraCloseParenShouldThrow()
        {
            SelectExpandParser parser = new SelectExpandParser("one($filter=true)), two", ODataUriParserSettings.DefaultSelectExpandLimit);
            Action             parse  = () => parser.ParseExpand();

            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriSelectParser_TermIsNotValid("one($filter=true)), two"));
        }
Пример #7
0
        public void SemicolonOnlyAllowedInParensInSelect()
        {
            SelectExpandParser parser = new SelectExpandParser("one;two", 3);
            Action             parse  = () => parser.ParseSelect();

            parse.ShouldThrow <ODataException>("one;two is not valid in a $select or $expand expression.");
        }
Пример #8
0
        public void SelectParsesEachTermOnce()
        {
            SelectExpandParser parser = new SelectExpandParser("foo,bar,thing,prop,yoda", ODataUriParserSettings.DefaultSelectExpandLimit);
            var results = parser.ParseSelect();

            results.Properties.Count().Should().Be(5);
        }
Пример #9
0
        public void NestedOptionsWithoutClosingParenthesisShouldThrow()
        {
            SelectExpandParser parser = new SelectExpandParser("one($filter=true", ODataUriParserSettings.DefaultSelectExpandLimit);
            Action             parse  = () => parser.ParseExpand();

            // TODO: Make this error message make sense for parenthetical expressions. Either generalize it or refactor code.
            parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_UnbalancedBracketExpression);
        }
Пример #10
0
        public void EmptyExpandStringBecomesEmptyList()
        {
            SelectExpandParser parser = new SelectExpandParser("", ODataUriParserSettings.DefaultSelectExpandLimit);
            var results = parser.ParseExpand();

            results.ExpandTerms.Should().NotBeNull();
            results.ExpandTerms.Should().BeEmpty();
        }
Пример #11
0
        public void JustSpaceSelectStringBecomesEmptyList()
        {
            SelectExpandParser parser = new SelectExpandParser("         ", ODataUriParserSettings.DefaultSelectExpandLimit);
            var results = parser.ParseSelect();

            results.Properties.Should().NotBeNull();
            results.Properties.Should().BeEmpty();
        }
Пример #12
0
        public void NestedOptionsOnMultipleExpansionsIsOk()
        {
            SelectExpandParser parser = new SelectExpandParser("one($filter=true), two($filter=false)", ODataUriParserSettings.DefaultSelectExpandLimit);
            var results = parser.ParseExpand();

            results.ExpandTerms.Should().HaveCount(2);
            results.ExpandTerms.First().FilterOption.Should().NotBeNull();
            results.ExpandTerms.Last().FilterOption.Should().NotBeNull();
        }
Пример #13
0
        public void WhitespaceInMiddleOfSegmentShouldThrowInSelect()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("what happens here/foo", 3);

            // Act
            Action test = () => parser.ParseSelect();

            // Assert
            test.Throws <ODataException>(Strings.UriSelectParser_TermIsNotValid("what happens here/foo"));
        }
Пример #14
0
        public void SemicolonOnlyAllowedInParensInSelect()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("one;two", 3);

            // Act
            Action test = () => parser.ParseSelect();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_InvalidCharacter(";", 3, "one;two"));
        }
Пример #15
0
        public void MaxRecursionDepthIsEnforcedInSelect()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("stuff/stuff/stuff/stuff", 3);

            // Act
            Action test = () => parser.ParseSelect();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.UriQueryExpressionParser_TooDeep);
        }
Пример #16
0
        public void ExpandParsesEachTermOnce()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("foo,bar,thing,prop,yoda", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            ExpandToken expandToken = parser.ParseExpand();

            // Assert
            Assert.Equal(5, expandToken.ExpandTerms.Count());
        }
Пример #17
0
        public void NestedOptionsWithExtraCloseParenShouldThrow()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("one($filter=true)), two", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            Action test = () => parser.ParseExpand();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.UriSelectParser_TermIsNotValid("one($filter=true)), two"));
        }
Пример #18
0
        public void EmptySelectTermShouldThrow()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("one,,two", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            Action test = () => parser.ParseSelect();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.ExpressionToken_IdentifierExpected("4"));
        }
Пример #19
0
        public void OpenCloseParensAfterNavPropShouldThrow()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("NavProp()", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            Action test = () => parser.ParseExpand();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.UriParser_MissingExpandOption("NavProp"));
        }
Пример #20
0
        public void NestedOptionsWithoutClosingParenthesisShouldThrow()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("one($filter=true", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            Action test = () => parser.ParseExpand();

            // Assert
            test.Throws <ODataException>(ODataErrorStrings.ExpressionLexer_UnbalancedBracketExpression);
        }
Пример #21
0
        public void SelectParsesEachTermOnce()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("foo,bar,thing,prop,yoda", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            SelectToken selectToken = parser.ParseSelect();

            // Assert
            Assert.Equal(5, selectToken.Properties.Count());
            Assert.Equal(5, selectToken.SelectTerms.Count());
        }
Пример #22
0
        public void NullOrEmptyOrWhitespaceExpandBecomesEmptyList(string clauseToParse)
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser(null, ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            ExpandToken expandToken = parser.ParseExpand();

            // Assert
            Assert.NotNull(expandToken.ExpandTerms);
            Assert.Empty(expandToken.ExpandTerms);
        }
Пример #23
0
        public void NullOrEmptyOrWhiteSpaceSelectBecomesEmptyList(string clauseToParse)
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser(clauseToParse, ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            SelectToken selectToken = parser.ParseSelect();

            // Assert
            Assert.NotNull(selectToken.Properties);
            Assert.Empty(selectToken.Properties);
            Assert.NotNull(selectToken.SelectTerms);
            Assert.Empty(selectToken.SelectTerms);
        }
Пример #24
0
        public void NestedOptionsOnMultipleExpansionsIsOk()
        {
            // Arrange
            SelectExpandParser parser = new SelectExpandParser("one($filter=true), two($filter=false)", ODataUriParserSettings.DefaultSelectExpandLimit);

            // Act
            ExpandToken expandToken = parser.ParseExpand();

            // Assert
            Assert.NotNull(expandToken);
            Assert.NotNull(expandToken.ExpandTerms);
            Assert.Equal(2, expandToken.ExpandTerms.Count());
            Assert.NotNull(expandToken.ExpandTerms.First().FilterOption);
            Assert.NotNull(expandToken.ExpandTerms.Last().FilterOption);
        }
Пример #25
0
        private SelectToken ParseSelectClause(string select)
        {
            ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(EdmCoreModel.Instance)
            {
                Settings = { PathLimit = 10, FilterLimit = 10, OrderByLimit = 10, SearchLimit = 10, SelectExpandLimit = 10 }
            };

            SelectExpandParser expandParser = new SelectExpandParser(select, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier)
            {
                MaxPathDepth    = configuration.Settings.PathLimit,
                MaxFilterDepth  = configuration.Settings.FilterLimit,
                MaxOrderByDepth = configuration.Settings.OrderByLimit,
                MaxSearchDepth  = configuration.Settings.SearchLimit
            };

            return(expandParser.ParseSelect());
        }
Пример #26
0
        private ExpandToken StarExpandTesting(string expand, String entitySetType)
        {
            IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(EdmCoreModel.Instance)
            {
                Settings = { PathLimit = 10, FilterLimit = 10, OrderByLimit = 10, SearchLimit = 10, SelectExpandLimit = 10 }
            };
            var parentEntityType            = configuration.Resolver.ResolveNavigationSource(model, entitySetType).EntityType();
            SelectExpandParser expandParser = new SelectExpandParser(configuration.Resolver, expand, parentEntityType, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier)
            {
                MaxPathDepth    = configuration.Settings.PathLimit,
                MaxFilterDepth  = configuration.Settings.FilterLimit,
                MaxOrderByDepth = configuration.Settings.OrderByLimit,
                MaxSearchDepth  = configuration.Settings.SearchLimit
            };

            return(expandParser.ParseExpand());
        }
Пример #27
0
        public void ParentEntityTypeIsNullForExpandStar()
        {
            var expand = "*";

            ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(EdmCoreModel.Instance)
            {
                Settings = { PathLimit = 10, FilterLimit = 10, OrderByLimit = 10, SearchLimit = 10, SelectExpandLimit = 10 }
            };

            SelectExpandParser expandParser = new SelectExpandParser(configuration.Resolver, expand, null, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier)
            {
                MaxPathDepth    = configuration.Settings.PathLimit,
                MaxFilterDepth  = configuration.Settings.FilterLimit,
                MaxOrderByDepth = configuration.Settings.OrderByLimit,
                MaxSearchDepth  = configuration.Settings.SearchLimit
            };

            Action action = () => expandParser.ParseExpand();

            action.ShouldThrow <ODataException>().WithMessage(Strings.UriExpandParser_ParentEntityIsNull(""));
        }
Пример #28
0
        private ExpandToken StarExpandTesting(string expand, string typeName, IEdmModel model = null)
        {
            if (model == null)
            {
                model = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            }

            ODataUriParserConfiguration configuration = new ODataUriParserConfiguration(EdmCoreModel.Instance)
            {
                Settings = { PathLimit = 10, FilterLimit = 10, OrderByLimit = 10, SearchLimit = 10, SelectExpandLimit = 10 }
            };

            var parentStructuredType        = configuration.Resolver.ResolveType(model, "TestModel." + typeName) as IEdmStructuredType;
            SelectExpandParser expandParser = new SelectExpandParser(configuration.Resolver, expand, parentStructuredType, configuration.Settings.SelectExpandLimit, configuration.EnableCaseInsensitiveUriFunctionIdentifier)
            {
                MaxPathDepth    = configuration.Settings.PathLimit,
                MaxFilterDepth  = configuration.Settings.FilterLimit,
                MaxOrderByDepth = configuration.Settings.OrderByLimit,
                MaxSearchDepth  = configuration.Settings.SearchLimit
            };

            return(expandParser.ParseExpand());
        }
        public static SelectToken ParseSelectToken(string select)
        {
            SelectExpandParser parser = new SelectExpandParser(select, ODataUriParserSettings.DefaultSelectExpandLimit);

            return(parser.ParseSelect());
        }
        public static ExpandToken ParseExpandToken(string expand)
        {
            SelectExpandParser parser = new SelectExpandParser(expand, ODataUriParserSettings.DefaultSelectExpandLimit);

            return(parser.ParseExpand());
        }