public void QueryOptionWithNullValueShouldWork() { var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary <string, string>() { { "$filter", null }, { "$expand", null }, { "$select", null }, { "$orderby", null }, { "$top", null }, { "$skip", null }, { "index", null }, { "$count", null }, { "$search", null }, { "$compute", null }, { "$unknow", null }, }); uriParser.ParseFilter().Should().BeNull(); uriParser.ParseSelectAndExpand().Should().BeNull(); uriParser.ParseOrderBy().Should().BeNull(); uriParser.ParseTop().Should().Be(null); uriParser.ParseSkip().Should().Be(null); uriParser.ParseIndex().Should().Be(null); uriParser.ParseCount().Should().Be(null); uriParser.ParseSearch().Should().BeNull(); uriParser.ParseCompute().Should().BeNull(); }
public void QueryOptionWithEmptyValueShouldWork() { var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary <string, string>() { { "$filter", "" }, { "$expand", "" }, { "$select", "" }, { "$orderby", "" }, { "$top", "" }, { "$skip", "" }, { "$count", "" }, { "$search", "" }, { "$compute", "" }, { "$unknow", "" }, }); uriParser.ParseFilter().Should().BeNull(); var results = uriParser.ParseSelectAndExpand(); results.AllSelected.Should().BeTrue(); results.SelectedItems.Should().HaveCount(0); uriParser.ParseOrderBy().Should().BeNull(); uriParser.ParseCompute().Should().BeNull(); Action action = () => uriParser.ParseTop(); action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidTopQueryOptionValue("")); action = () => uriParser.ParseSkip(); action.ShouldThrow <ODataException>().WithMessage(Strings.SyntacticTree_InvalidSkipQueryOptionValue("")); action = () => uriParser.ParseCount(); action.ShouldThrow <ODataException>().WithMessage(Strings.ODataUriParser_InvalidCount("")); action = () => uriParser.ParseSearch(); action.ShouldThrow <ODataException>().WithMessage(Strings.UriQueryExpressionParser_ExpressionExpected(0, "")); }
public void EmptyQueryOptionDictionaryShouldWork() { var uriParser = new ODataQueryOptionParser(HardCodedTestModel.TestModel, HardCodedTestModel.GetPersonType(), HardCodedTestModel.GetPeopleSet(), new Dictionary <string, string>()); uriParser.ParseFilter().Should().BeNull(); uriParser.ParseSelectAndExpand().Should().BeNull(); uriParser.ParseOrderBy().Should().BeNull(); uriParser.ParseTop().Should().Be(null); uriParser.ParseSkip().Should().Be(null); uriParser.ParseCount().Should().Be(null); uriParser.ParseSearch().Should().BeNull(); uriParser.ParseCompute().Should().BeNull(); }
private static QueryClause CreateQueryClause(string query, IEdmModel model, Type type) { IEdmEntityType entityType = model.SchemaElements.OfType <IEdmEntityType>().Single(t => t.Name == type.Name); Assert.NotNull(entityType); // Guard IEdmEntitySet entitySet = model.EntityContainer.FindEntitySet("Customers"); Assert.NotNull(entitySet); // Guard string[] queryItems = query.Split('&'); Dictionary <string, string> queries = new Dictionary <string, string>(); foreach (string item in queryItems) { if (item.StartsWith("$select=", StringComparison.Ordinal)) { queries["$select"] = item.Substring(8); } else if (item.StartsWith("$expand=", StringComparison.Ordinal)) { queries["$expand"] = item.Substring(8); } else if (item.StartsWith("$filter=", StringComparison.Ordinal)) { queries["$filter"] = item.Substring(8); } else if (item.StartsWith("$orderby=", StringComparison.Ordinal)) { queries["$orderby"] = item.Substring(9); } else if (item.StartsWith("$compute=", StringComparison.Ordinal)) { queries["$compute"] = item.Substring(9); } } ODataQueryOptionParser parser = new ODataQueryOptionParser(model, entityType, entitySet, queries); return(new QueryClause { Filter = parser.ParseFilter(), OrderBy = parser.ParseOrderBy(), SelectExpand = parser.ParseSelectAndExpand(), Compute = parser.ParseCompute() }); }
internal void AddAutoSelectExpandProperties() { bool containsAutoSelectExpandProperties = false; var autoExpandRawValue = GetAutoExpandRawValue(); var autoSelectRawValue = GetAutoSelectRawValue(); IDictionary <string, string> queryParameters = GetODataQueryParameters(); if (!String.IsNullOrEmpty(autoExpandRawValue) && !autoExpandRawValue.Equals(RawValues.Expand)) { queryParameters["$expand"] = autoExpandRawValue; containsAutoSelectExpandProperties = true; } else { autoExpandRawValue = RawValues.Expand; } if (!String.IsNullOrEmpty(autoSelectRawValue) && !autoSelectRawValue.Equals(RawValues.Select)) { queryParameters["$select"] = autoSelectRawValue; containsAutoSelectExpandProperties = true; } else { autoSelectRawValue = RawValues.Select; } if (containsAutoSelectExpandProperties) { _queryOptionParser = new ODataQueryOptionParser( Context.Model, Context.ElementType, Context.NavigationSource, queryParameters, Context.RequestContainer ); if (Apply != null) { _queryOptionParser.ParseApply(); } if (Compute != null) { _queryOptionParser.ParseCompute(); } var originalSelectExpand = SelectExpand; SelectExpand = new SelectExpandQueryOption( autoSelectRawValue, autoExpandRawValue, Context, _queryOptionParser); var typeLevelModelSettings = EdmLibHelpers.GetModelBoundQuerySettings(this.Context.ElementType, this.Context.Model, this.Context.DefaultQuerySettings); SelectExpand.SelectExpandClause.AllAutoSelected = (typeLevelModelSettings != null && typeLevelModelSettings.DefaultSelectType == SelectExpandType.Automatic); if (originalSelectExpand != null && originalSelectExpand.LevelsMaxLiteralExpansionDepth > 0) { SelectExpand.LevelsMaxLiteralExpansionDepth = originalSelectExpand.LevelsMaxLiteralExpansionDepth; } } }