public void SemicolonOnlyAllowedInParensInExpand() { SelectExpandParser parser = new SelectExpandParser("one;two", 3); Action parse = () => parser.ParseExpand(); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionLexer_InvalidCharacter(";", 3, "one;two")); }
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")); }
public void OpenCloseParensAfterNavPropShouldThrow() { SelectExpandParser parser = new SelectExpandParser("NavProp()", ODataUriParserSettings.DefaultSelectExpandLimit); Action parse = () => parser.ParseExpand(); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriParser_MissingExpandOption("NavProp")); }
public void MaxRecursionDepthIsEnforcedInExpand() { SelectExpandParser parser = new SelectExpandParser("stuff/stuff/stuff/stuff", 3); Action parse = () => parser.ParseExpand(); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.UriQueryExpressionParser_TooDeep); }
public void EmptyExpandTermShouldThrow() { SelectExpandParser parser = new SelectExpandParser("one,,two", ODataUriParserSettings.DefaultSelectExpandLimit); Action parse = () => parser.ParseExpand(); parse.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.ExpressionToken_IdentifierExpected("4")); }
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")); }
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."); }
public void SelectParsesEachTermOnce() { SelectExpandParser parser = new SelectExpandParser("foo,bar,thing,prop,yoda", ODataUriParserSettings.DefaultSelectExpandLimit); var results = parser.ParseSelect(); results.Properties.Count().Should().Be(5); }
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); }
public void EmptyExpandStringBecomesEmptyList() { SelectExpandParser parser = new SelectExpandParser("", ODataUriParserSettings.DefaultSelectExpandLimit); var results = parser.ParseExpand(); results.ExpandTerms.Should().NotBeNull(); results.ExpandTerms.Should().BeEmpty(); }
public void JustSpaceSelectStringBecomesEmptyList() { SelectExpandParser parser = new SelectExpandParser(" ", ODataUriParserSettings.DefaultSelectExpandLimit); var results = parser.ParseSelect(); results.Properties.Should().NotBeNull(); results.Properties.Should().BeEmpty(); }
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(); }
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")); }
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")); }
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); }
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()); }
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")); }
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")); }
public void OpenCloseParensAfterNavPropShouldThrow() { // Arrange SelectExpandParser parser = new SelectExpandParser("NavProp()", ODataUriParserSettings.DefaultSelectExpandLimit); // Act Action test = () => parser.ParseExpand(); // Assert test.Throws <ODataException>(ODataErrorStrings.UriParser_MissingExpandOption("NavProp")); }
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); }
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()); }
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); }
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); }
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); }
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()); }
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()); }
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("")); }
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()); }