Exemplo n.º 1
0
 public static string BindFilterQueryOption(FilterQueryOption filterQuery)
 {
     if (filterQuery != null)
     {
         SQLFilterBinder binder = new SQLFilterBinder(filterQuery.Context.Model);
         return binder.BindFilter(filterQuery) + Environment.NewLine;
     }
     return string.Empty;
 }
        public static WhereClause BindFilterQueryOption(FilterQueryOption filterQuery)
        {
            if (filterQuery != null)
            {
                NHibernateFilterBinder binder = new NHibernateFilterBinder(filterQuery.Context.Model);
                return new WhereClause
                {
                    Clause = "where " + binder.BindFilter(filterQuery) + Environment.NewLine,
                    PositionalParameters = binder._positionalParmeters.ToArray()
                };
            }

            return _emptyWhereClause;
        }
Exemplo n.º 3
0
        public void ApplyToEnums_DoesnotThrow_ForUndefinedValue(string filter)
        {
            // Arrange
            var model        = GetEnumModel();
            var context      = new ODataQueryContext(model, typeof(EnumModel));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <EnumModel> enumModels = EnumModelTestData;

            // Act
            Assert.DoesNotThrow(
                () => filterOption.ApplyTo(enumModels.AsQueryable(),
                                           new ODataQuerySettings
            {
                HandleNullPropagation = HandleNullPropagationOption.True
            })
                );
        }
Exemplo n.º 4
0
        public void ApplyWithCast_Throws_WithInvalidFilter(string filter, Type exceptionType)
        {
            // Arrange
            var model        = GetCastModel();
            var context      = new ODataQueryContext(model, typeof(DataTypes));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <DataTypes> castModels = CastModelTestData;

            // Act & Assert
            Assert.Throws(
                exceptionType,
                () => filterOption.ApplyTo(
                    castModels.AsQueryable(),
                    new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            }));
        }
Exemplo n.º 5
0
        public void GetQueryNodeParsesQuery()
        {
            var model   = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filter  = new FilterQueryOption("Name eq 'MSFT'", context);
            var node    = filter.FilterClause;

            Assert.Equal(QueryNodeKind.BinaryOperator, node.Expression.Kind);
            var binaryNode = node.Expression as BinaryOperatorNode;

            Assert.Equal(BinaryOperatorKind.Equal, binaryNode.OperatorKind);
            Assert.Equal(QueryNodeKind.Constant, binaryNode.Right.Kind);
            Assert.Equal("MSFT", ((ConstantNode)binaryNode.Right).Value);
            Assert.Equal(QueryNodeKind.SingleValuePropertyAccess, binaryNode.Left.Kind);
            var propertyAccessNode = binaryNode.Left as SingleValuePropertyAccessNode;

            Assert.Equal("Name", propertyAccessNode.Property.Name);
        }
Exemplo n.º 6
0
        public void CanConstructValidAnyQueryOverComplexCollectionProperty()
        {
            var model   = new ODataModelBuilder().Add_Customer_EntityType_With_CollectionProperties().Add_Customers_EntitySet().Add_Address_ComplexType().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer))
            {
                RequestContainer = new MockContainer()
            };
            var filter         = new FilterQueryOption("Addresses/any(a: a/HouseNumber eq 1)", context);
            var node           = filter.FilterClause;
            var anyNode        = node.Expression as AnyNode;
            var aParameter     = anyNode.RangeVariables.SingleOrDefault(p => p.Name == "a");
            var aParameterType = aParameter.TypeReference.Definition as IEdmComplexType;

            Assert.NotNull(aParameter);

            Assert.NotNull(aParameterType);
            Assert.Equal("a", aParameter.Name);
        }
Exemplo n.º 7
0
        public void ApplyToEnums_ThrowsNotSupported_ForStringFunctions(string filter, string exceptionMessage)
        {
            // Arrange
            var model   = GetEnumModel();
            var context = new ODataQueryContext(model, typeof(EnumModel))
            {
                RequestContainer = new MockContainer()
            };
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <EnumModel> enumModels = EnumModelTestData;

            // Act
            Assert.Throws <ODataException>(
                () => filterOption.ApplyTo(enumModels.AsQueryable(), new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            }),
                exceptionMessage
                );
        }
Exemplo n.º 8
0
        public void ApplyWithCast_ShouldWork_WithStringToEnumConversionFilter()
        {
            // Arrange
            string filter  = "cast('123',Microsoft.TestCommon.Types.SimpleEnum) ne 'First'";
            var    model   = GetCastModel();
            var    context = new ODataQueryContext(model, typeof(DataTypes))
            {
                RequestContainer = new MockContainer()
            };
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <DataTypes> castModels = CastModelTestData;

            // Act & Assert
            filterOption.ApplyTo(
                castModels.AsQueryable(),
                new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            });
        }
Exemplo n.º 9
0
        public void ApplyToEnums_Throws_WithInvalidFilter(string filter, Type exceptionType)
        {
            // Arrange
            var model   = GetEnumModel();
            var context = new ODataQueryContext(model, typeof(EnumModel))
            {
                RequestContainer = new MockContainer()
            };
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <EnumModel> enumModels = EnumModelTestData;

            // Act & Assert
            Assert.Throws(
                exceptionType,
                () => filterOption.ApplyTo(
                    enumModels.AsQueryable(),
                    new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            }));
        }
Exemplo n.º 10
0
        public void ApplyWithCast_ReturnsCorrectQueryable(string filter, int[] castModelIds)
        {
            // Arrange
            var model        = GetCastModel();
            var context      = new ODataQueryContext(model, typeof(DataTypes));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <DataTypes> castModels = CastModelTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(castModels.AsQueryable(), new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable <DataTypes> actualProducts = Assert.IsAssignableFrom <IEnumerable <DataTypes> >(queryable);

            Assert.Equal(
                castModelIds,
                actualProducts.Select(product => product.IntProp));
        }
Exemplo n.º 11
0
        public void ApplyToEnums_ReturnsCorrectQueryable(string filter, int[] enumModelIds)
        {
            // Arrange
            var model        = GetEnumModel();
            var context      = new ODataQueryContext(model, typeof(EnumModel));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <EnumModel> enumModels = EnumModelTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(enumModels.AsQueryable(), new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable <EnumModel> actualCustomers = Assert.IsAssignableFrom <IEnumerable <EnumModel> >(queryable);

            Assert.Equal(
                enumModelIds,
                actualCustomers.Select(enumModel => enumModel.Id));
        }
Exemplo n.º 12
0
        public void ApplyTo_ReturnsCorrectQueryable_PropertyAlias(string filter, int[] propertyAliasIds)
        {
            // Arrange
            var model        = GetPropertyAliasModel();
            var context      = new ODataQueryContext(model, typeof(PropertyAlias));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable <PropertyAlias> propertyAliases = PropertyAliasTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(
                propertyAliases.AsQueryable(),
                new ODataQuerySettings {
                HandleNullPropagation = HandleNullPropagationOption.True
            });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable <PropertyAlias> actualPropertyAliases = Assert.IsAssignableFrom <IEnumerable <PropertyAlias> >(queryable);

            Assert.Equal(
                propertyAliasIds,
                actualPropertyAliases.Select(propertyAlias => propertyAlias.Id));
        }
        public void ApplyWithParameterAlias_ReturnsCorrectQueryable(string filter, string parameterAliasValue, int[] parameterAliasModelIds)
        {
            // Arrange
            var model = GetParameterAliasModel();
            var context = new ODataQueryContext(model, typeof(DataTypes));
            IEdmType targetEdmType = model.FindType("System.Web.OData.Query.Expressions.DataTypes");
            IEdmNavigationSource targetNavigationSource = model.FindDeclaredEntitySet("System.Web.OData.Query.Expressions.Products");

            ODataQueryOptionParser parser = new ODataQueryOptionParser(
                model,
                targetEdmType,
                targetNavigationSource,
                new Dictionary<string, string> { { "$filter", filter }, { "@p", parameterAliasValue } });

            var filterOption = new FilterQueryOption(filter, context, parser);
            IEnumerable<DataTypes> parameterAliasModels = ParameterAliasTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(parameterAliasModels.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable<DataTypes> actualResult = Assert.IsAssignableFrom<IEnumerable<DataTypes>>(queryable);
            Assert.Equal(
                parameterAliasModelIds,
                actualResult.Select(result => result.IntProp));
        }
        public void ApplyWithCast_Throws_WithInvalidFilter(string filter, Type exceptionType)
        {
            // Arrange
            var model = GetCastModel();
            var context = new ODataQueryContext(model, typeof(DataTypes));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<DataTypes> castModels = CastModelTestData;

            // Act & Assert
            Assert.Throws(
                exceptionType,
                () => filterOption.ApplyTo(
                    castModels.AsQueryable(),
                    new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True }));
        }
        public void ApplyToEnums_ThrowsNotSupported_ForStringFunctions(string filter, string exceptionMessage)
        {
            // Arrange
            var model = GetEnumModel();
            var context = new ODataQueryContext(model, typeof(EnumModel));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<EnumModel> enumModels = EnumModelTestData;

            // Act
            Assert.Throws<ODataException>(
                () => filterOption.ApplyTo(enumModels.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True }),
                exceptionMessage
            );
        }
        public void ApplyToEnums_DoesnotThrow_ForUndefinedValue(string filter)
        {
            // Arrange
            var model = GetEnumModel();
            var context = new ODataQueryContext(model, typeof(EnumModel));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<EnumModel> enumModels = EnumModelTestData;

            // Act
            Assert.DoesNotThrow(
                () => filterOption.ApplyTo(enumModels.AsQueryable(),
                    new ODataQuerySettings
                    {
                        HandleNullPropagation = HandleNullPropagationOption.True
                    })
            );
        }
        public void ApplyWithCast_ReturnsCorrectQueryable(string filter, int[] castModelIds)
        {
            // Arrange
            var model = GetCastModel();
            var context = new ODataQueryContext(model, typeof(DataTypes));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<DataTypes> castModels = CastModelTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(castModels.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable<DataTypes> actualProducts = Assert.IsAssignableFrom<IEnumerable<DataTypes>>(queryable);
            Assert.Equal(
                castModelIds,
                actualProducts.Select(product => product.IntProp));
        }
 private static WhereClause ToFilterQuery(FilterQueryOption filterQuery)
 {
     return NHibernateFilterBinder.BindFilterQueryOption(filterQuery);
 }
        public void ApplyToEnums_ReturnsCorrectQueryable(string filter, int[] enumModelIds)
        {
            // Arrange
            var model = GetEnumModel();
            var context = new ODataQueryContext(model, typeof(EnumModel));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<EnumModel> enumModels = EnumModelTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(enumModels.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable<EnumModel> actualCustomers = Assert.IsAssignableFrom<IEnumerable<EnumModel>>(queryable);
            Assert.Equal(
                enumModelIds,
                actualCustomers.Select(enumModel => enumModel.Id));
        }
        public void CanTurnOffValidationForFilter()
        {
            ODataValidationSettings settings = new ODataValidationSettings() { AllowedFunctions = AllowedFunctions.AllDateTimeFunctions };
            ODataQueryContext context = ValidationTestHelper.CreateCustomerContext();
            FilterQueryOption option = new FilterQueryOption("substring(Name,8,1) eq '7'", context);

            Assert.Throws<ODataException>(() =>
                option.Validate(settings),
                "Function 'substring' is not allowed. To allow it, set the 'AllowedFunctions' property on EnableQueryAttribute or QueryValidationSettings.");

            option.Validator = null;
            Assert.DoesNotThrow(() => option.Validate(settings));
        }
        public void ApplyTo_Throws_Null_AssembliesResolver()
        {
            // Arrange
            var model = new ODataModelBuilder().Add_Customer_EntityType_With_CollectionProperties().Add_Customers_EntitySet().Add_Address_ComplexType().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filter = new FilterQueryOption("Addresses/any(a: a/HouseNumber eq 1)", context);

            // Act & Assert
            Assert.ThrowsArgumentNull(() => filter.ApplyTo(new Customer[0].AsQueryable(), new ODataQuerySettings(), null), "assembliesResolver");
        }
        public void GetQueryNodeParsesQuery()
        {
            var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filter = new FilterQueryOption("Name eq 'MSFT'", context);
            var node = filter.FilterClause;

            Assert.Equal(QueryNodeKind.BinaryOperator, node.Expression.Kind);
            var binaryNode = node.Expression as BinaryOperatorNode;
            Assert.Equal(BinaryOperatorKind.Equal, binaryNode.OperatorKind);
            Assert.Equal(QueryNodeKind.Constant, binaryNode.Right.Kind);
            Assert.Equal("MSFT", ((ConstantNode)binaryNode.Right).Value);
            Assert.Equal(QueryNodeKind.SingleValuePropertyAccess, binaryNode.Left.Kind);
            var propertyAccessNode = binaryNode.Left as SingleValuePropertyAccessNode;
            Assert.Equal("Name", propertyAccessNode.Property.Name);
        }
        public void CanConstructValidAnyQueryOverComplexCollectionProperty()
        {
            var model = new ODataModelBuilder().Add_Customer_EntityType_With_CollectionProperties().Add_Customers_EntitySet().Add_Address_ComplexType().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filter = new FilterQueryOption("Addresses/any(a: a/HouseNumber eq 1)", context);
            var node = filter.FilterClause;
            var anyNode = node.Expression as AnyNode;
            var aParameter = anyNode.RangeVariables.SingleOrDefault(p => p.Name == "a");
            var aParameterType = aParameter.TypeReference.Definition as IEdmComplexType;

            Assert.NotNull(aParameter);

            Assert.NotNull(aParameterType);
            Assert.Equal("a", aParameter.Name);
        }
 protected string BindFilter(FilterQueryOption filterQuery)
 {
     return BindFilterClause(filterQuery.FilterClause);
 }
        public void ApplyTo_WithUnTypedContext_Throws_InvalidOperation()
        {
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer);
            FilterQueryOption filter = new FilterQueryOption("Id eq 42", context);
            IQueryable queryable = new Mock<IQueryable>().Object;

            Assert.Throws<NotSupportedException>(() => filter.ApplyTo(queryable, new ODataQuerySettings()),
                "The query option is not bound to any CLR type. 'ApplyTo' is only supported with a query option bound to a CLR type.");
        }
Exemplo n.º 26
0
        public override void Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)
        {
            base.Validate(filterQueryOption, settings);

            if (!visited)
            {
                throw new ODataException("$filter query must contain ID property");
            }
        }
        public void ApplyTo_ReturnsCorrectQueryable_PropertyAlias(string filter, int[] propertyAliasIds)
        {
            // Arrange
            var model = GetPropertyAliasModel();
            var context = new ODataQueryContext(model, typeof(PropertyAlias));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<PropertyAlias> propertyAliases = PropertyAliasTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(
                propertyAliases.AsQueryable(),
                new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable<PropertyAlias> actualPropertyAliases = Assert.IsAssignableFrom<IEnumerable<PropertyAlias>>(queryable);
            Assert.Equal(
                propertyAliasIds,
                actualPropertyAliases.Select(propertyAlias => propertyAlias.Id));
        }
        public void ApplyTo_Returns_Correct_Queryable(string filter, int[] customerIds)
        {
            // Arrange
            var model = new ODataModelBuilder()
                            .Add_Order_EntityType()
                            .Add_Customer_EntityType_With_Address()
                            .Add_CustomerOrders_Relationship()
                            .Add_Customer_EntityType_With_CollectionProperties()
                            .Add_Customers_EntitySet()
                            .GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filterOption = new FilterQueryOption(filter, context);
            IEnumerable<Customer> customers = CustomerFilterTestData;

            // Act
            IQueryable queryable = filterOption.ApplyTo(customers.AsQueryable(), new ODataQuerySettings { HandleNullPropagation = HandleNullPropagationOption.True });

            // Assert
            Assert.NotNull(queryable);
            IEnumerable<Customer> actualCustomers = Assert.IsAssignableFrom<IEnumerable<Customer>>(queryable);
            Assert.Equal(
                customerIds,
                actualCustomers.Select(customer => customer.CustomerId));
        }
        public void Property_FilterClause_WorksWithUnTypedContext()
        {
            // Arrange
            CustomersModelWithInheritance model = new CustomersModelWithInheritance();
            ODataQueryContext context = new ODataQueryContext(model.Model, model.Customer);
            FilterQueryOption filter = new FilterQueryOption("ID eq 42", context);

            // Act & Assert
            Assert.NotNull(filter.FilterClause);
        }
Exemplo n.º 30
0
        private void BuildQueryOptions(IDictionary <string, string> queryParameters)
        {
            foreach (KeyValuePair <string, string> kvp in queryParameters)
            {
                switch (kvp.Key.ToLowerInvariant())
                {
                case "$filter":
                    ThrowIfEmpty(kvp.Value, "$filter");
                    RawValues.Filter = kvp.Value;
                    Filter           = new FilterQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                case "$orderby":
                    ThrowIfEmpty(kvp.Value, "$orderby");
                    RawValues.OrderBy = kvp.Value;
                    OrderBy           = new OrderByQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                case "$top":
                    ThrowIfEmpty(kvp.Value, "$top");
                    RawValues.Top = kvp.Value;
                    Top           = new TopQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                case "$skip":
                    ThrowIfEmpty(kvp.Value, "$skip");
                    RawValues.Skip = kvp.Value;
                    Skip           = new SkipQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                case "$select":
                    RawValues.Select = kvp.Value;
                    break;

                case "$count":
                    ThrowIfEmpty(kvp.Value, "$count");
                    RawValues.Count = kvp.Value;
                    Count           = new CountQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                case "$expand":
                    RawValues.Expand = kvp.Value;
                    break;

                case "$format":
                    RawValues.Format = kvp.Value;
                    break;

                case "$skiptoken":
                    RawValues.SkipToken = kvp.Value;
                    break;

                case "$deltatoken":
                    RawValues.DeltaToken = kvp.Value;
                    break;

                case "$apply":
                    ThrowIfEmpty(kvp.Value, "$apply");
                    RawValues.Apply = kvp.Value;
                    Apply           = new ApplyQueryOption(kvp.Value, Context, _queryOptionParser);
                    break;

                default:
                    // we don't throw if we can't recognize the query
                    break;
                }
            }

            if (RawValues.Select != null || RawValues.Expand != null)
            {
                SelectExpand = new SelectExpandQueryOption(RawValues.Select, RawValues.Expand,
                                                           Context, _queryOptionParser);
            }

            if (ODataCountMediaTypeMapping.IsCountRequest(Request))
            {
                Count = new CountQueryOption(
                    "true",
                    Context,
                    new ODataQueryOptionParser(
                        Context.Model,
                        Context.ElementType,
                        Context.NavigationSource,
                        new Dictionary <string, string> {
                    { "$count", "true" }
                }));
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ODataQueryOptions"/> class based on the incoming request and some metadata information from
        /// the <see cref="ODataQueryContext"/>.
        /// </summary>
        /// <param name="context">The <see cref="ODataQueryContext"/> which contains the <see cref="IEdmModel"/> and some type information.</param>
        /// <param name="request">The incoming request message.</param>
        public ODataQueryOptions(ODataQueryContext context, HttpRequestMessage request)
        {
            if (context == null)
            {
                throw Error.ArgumentNull("context");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (request.GetConfiguration() != null)
            {
                _assembliesResolver = request.GetConfiguration().Services.GetAssembliesResolver();
            }

            // fallback to the default assemblies resolver if none available.
            _assembliesResolver = _assembliesResolver ?? new DefaultAssembliesResolver();

            // remember the context and request
            Context = context;
            Request = request;

            // Parse the query from request Uri
            RawValues = new ODataRawQueryOptions();
            IEnumerable <KeyValuePair <string, string> > queryParameters = request.GetQueryNameValuePairs();

            foreach (KeyValuePair <string, string> kvp in queryParameters)
            {
                switch (kvp.Key)
                {
                case "$filter":
                    ThrowIfEmpty(kvp.Value, "$filter");
                    RawValues.Filter = kvp.Value;
                    Filter           = new FilterQueryOption(kvp.Value, context);
                    break;

                case "$orderby":
                    ThrowIfEmpty(kvp.Value, "$orderby");
                    RawValues.OrderBy = kvp.Value;
                    OrderBy           = new OrderByQueryOption(kvp.Value, context);
                    break;

                case "$top":
                    ThrowIfEmpty(kvp.Value, "$top");
                    RawValues.Top = kvp.Value;
                    Top           = new TopQueryOption(kvp.Value, context);
                    break;

                case "$skip":
                    ThrowIfEmpty(kvp.Value, "$skip");
                    RawValues.Skip = kvp.Value;
                    Skip           = new SkipQueryOption(kvp.Value, context);
                    break;

                case "$select":
                    RawValues.Select = kvp.Value;
                    break;

                case "$count":
                    ThrowIfEmpty(kvp.Value, "$count");
                    RawValues.Count = kvp.Value;
                    Count           = new CountQueryOption(kvp.Value, context);
                    break;

                case "$expand":
                    RawValues.Expand = kvp.Value;
                    break;

                case "$format":
                    RawValues.Format = kvp.Value;
                    break;

                case "$skiptoken":
                    RawValues.SkipToken = kvp.Value;
                    break;

                default:
                    // we don't throw if we can't recognize the query
                    break;
                }
            }

            if (RawValues.Select != null || RawValues.Expand != null)
            {
                SelectExpand = new SelectExpandQueryOption(RawValues.Select, RawValues.Expand, context);
            }

            Validator = new ODataQueryValidator();
        }
        public void CanConstructValidFilterQuery(string filterValue)
        {
            var model = new ODataModelBuilder().Add_Customer_EntityType().Add_Customers_EntitySet().GetEdmModel();
            var context = new ODataQueryContext(model, typeof(Customer));
            var filter = new FilterQueryOption(filterValue, context);

            Assert.Same(context, filter.Context);
            Assert.Equal(filterValue, filter.RawValue);
        }