当前位置: 首页>>代码示例>>C#>>正文


C# FilterQueryOption类代码示例

本文整理汇总了C#中FilterQueryOption的典型用法代码示例。如果您正苦于以下问题:C# FilterQueryOption类的具体用法?C# FilterQueryOption怎么用?C# FilterQueryOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


FilterQueryOption类属于命名空间,在下文中一共展示了FilterQueryOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validate

        /// <summary>
        /// The entry point of this validator class. Use this method to validate the FilterQueryOption
        /// </summary>
        public virtual void Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)
        {
            if (filterQueryOption == null)
            {
                throw Error.ArgumentNull("filterQueryOption");
            }

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

            ValidateQueryNode(filterQueryOption.FilterClause.Expression, settings);
        }
开发者ID:jlamfers,项目名称:aspnetwebstack,代码行数:17,代码来源:FilterQueryValidator.cs

示例2: Validate

        /// <summary>
        /// Validates a <see cref="FilterQueryOption" />.
        /// </summary>
        /// <param name="filterQueryOption">The $filter query.</param>
        /// <param name="settings">The validation settings.</param>
        /// <remarks>
        /// Please note this method is not thread safe.
        /// </remarks>
        public virtual void Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)
        {
            if (filterQueryOption == null)
            {
                throw Error.ArgumentNull("filterQueryOption");
            }

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

            _currentAnyAllExpressionDepth = 0;
            _currentNodeCount = 0;
            _model = filterQueryOption.Context.Model;

            ValidateQueryNode(filterQueryOption.FilterClause.Expression, settings);
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:26,代码来源:FilterQueryValidator.cs

示例3: ValidateVisitAny

        public void ValidateVisitAny()
        {
            // Arrange
            FilterQueryOption option = new FilterQueryOption("Tags/any(t: t eq '42')", _context);

            // Act
            _validator.Validate(option, _settings);

            // Assert
            Assert.Equal(7, _validator.Times.Keys.Count);
            Assert.Equal(1, _validator.Times["Validate"]); // entry
            Assert.Equal(1, _validator.Times["ValidateAnyQueryNode"]); // all
            Assert.Equal(1, _validator.Times["ValidateLogicalOperator"]); // eq
            Assert.Equal(1, _validator.Times["ValidateCollectionPropertyAccessNode"]); // Tags
            Assert.Equal(1, _validator.Times["ValidateConstantQueryNode"]); // 42
            Assert.Equal(1, _validator.Times["ValidateBinaryOperatorQueryNode"]); // eq
            Assert.Equal(2, _validator.Times["ValidateParameterQueryNode"]); // $it, t
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:18,代码来源:FilterQueryValidatorTest.cs

示例4: Functions_CheckArguments_SucceedIfAllowed

        public void Functions_CheckArguments_SucceedIfAllowed(AllowedFunctions outer, AllowedFunctions inner, string query, string unused)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = outer | inner,
            };
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.DoesNotThrow(() => _validator.Validate(option, settings));
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:12,代码来源:FilterQueryValidatorTest.cs

示例5: OtherFunctions_SomeSingleParameterCasts_ThrowODataException

        public void OtherFunctions_SomeSingleParameterCasts_ThrowODataException(AllowedFunctions unused, string query, string unusedName)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.None,
            };
            var expectedMessage = "Cast or IsOf Function must have a type in its arguments.";
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.Throws<ODataException>(() => _validator.Validate(option, settings), expectedMessage);
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:13,代码来源:FilterQueryValidatorTest.cs

示例6: OtherFunctions_UnsupportedTargetType_ThrowODataException

        public void OtherFunctions_UnsupportedTargetType_ThrowODataException(string query, string targetType)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.None,
            };
            var expectedMessage = string.Format(
                "The child type '{0}' in a cast was not an entity type. Casts can only be performed on entity types.",
                targetType);
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.Throws<ODataException>(() => _validator.Validate(option, settings), expectedMessage);
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:15,代码来源:FilterQueryValidatorTest.cs

示例7: StringFunctions_SucceedIfGroupAllowed

        public void StringFunctions_SucceedIfGroupAllowed(AllowedFunctions unused, string query, string unusedName)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.AllStringFunctions,
            };
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.DoesNotThrow(() => _validator.Validate(option, settings));
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:12,代码来源:FilterQueryValidatorTest.cs

示例8: ArithmeticOperators_CheckArguments_SucceedIfAllowed

        public void ArithmeticOperators_CheckArguments_SucceedIfAllowed(string query)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.Day,
            };
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.DoesNotThrow(() => _validator.Validate(option, settings));
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:12,代码来源:FilterQueryValidatorTest.cs

示例9: AllowedArithmeticOperators_SucceedIfAllowed

        public void AllowedArithmeticOperators_SucceedIfAllowed(AllowedArithmeticOperators allow, string query, string unused)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedArithmeticOperators = allow,
            };
            var option = new FilterQueryOption(query, _productContext);

            // Act & Assert
            Assert.DoesNotThrow(() => _validator.Validate(option, settings));
        }
开发者ID:AndreGleichner,项目名称:aspnetwebstack,代码行数:12,代码来源:FilterQueryValidatorTest.cs

示例10: ValidateVisitLogicalOperatorHas

        public void ValidateVisitLogicalOperatorHas()
        {
            // Arrange
            FilterQueryOption option = new FilterQueryOption("FavoriteColor has System.Web.OData.Builder.TestModels.Color'Red'", _context);

            // Act
            _validator.Validate(option, _settings);

            // Assert
            Assert.Equal(6, _validator.Times.Keys.Count);
            Assert.Equal(1, _validator.Times["Validate"]); // entry
            Assert.Equal(1, _validator.Times["ValidateSingleValuePropertyAccessNode"]); // FavouriteColor
            Assert.Equal(1, _validator.Times["ValidateLogicalOperator"]); // has
            Assert.Equal(1, _validator.Times["ValidateBinaryOperatorQueryNode"]); // has
            Assert.Equal(1, _validator.Times["ValidateParameterQueryNode"]); // $it
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:FilterQueryValidatorTest.cs

示例11: AllowedLogicalOperators_ThrowsOnNotAllowedOperators

        public void AllowedLogicalOperators_ThrowsOnNotAllowedOperators()
        {
            // Arrange
            ODataValidationSettings settings = new ODataValidationSettings
            {
                AllowedLogicalOperators = AllowedLogicalOperators.All & ~AllowedLogicalOperators.NotEqual
            };

            FilterQueryOption option = new FilterQueryOption("length(ProductName) ne 6", _productContext);

            // Act & Assert
            Assert.Throws<ODataException>(
                () => _validator.Validate(option, settings),
                "Logical operator 'NotEqual' is not allowed. To allow it, set the 'AllowedLogicalOperators' property on EnableQueryAttribute or QueryValidationSettings.");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:15,代码来源:FilterQueryValidatorTest.cs

示例12: AllowedFunctions_ThrowsOnNotAllowedFunctions

        public void AllowedFunctions_ThrowsOnNotAllowedFunctions()
        {
            // Arrange
            ODataValidationSettings settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.All & ~AllowedFunctions.Length
            };

            FilterQueryOption option = new FilterQueryOption("length(ProductName) eq 6", _productContext);

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

        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:16,代码来源:FilterQueryValidatorTest.cs

示例13: AllowedArithmeticOperators_ThrowsOnNotAllowedOperators

        public void AllowedArithmeticOperators_ThrowsOnNotAllowedOperators()
        {
            // Arrange
            ODataValidationSettings settings = new ODataValidationSettings
            {
                AllowedArithmeticOperators = AllowedArithmeticOperators.All & ~AllowedArithmeticOperators.Modulo
            };

            FilterQueryOption option = new FilterQueryOption("ProductID mod 2 eq 0", _productContext);

            // Act & Assert
            Assert.Throws<ODataException>(
                () => _validator.Validate(option, settings),
                "Arithmetic operator 'Modulo' is not allowed. To allow it, set the 'AllowedArithmeticOperators' property on EnableQueryAttribute or QueryValidationSettings.");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:15,代码来源:FilterQueryValidatorTest.cs

示例14: MathFunctions_ThrowIfGroupNotAllowed

        public void MathFunctions_ThrowIfGroupNotAllowed(AllowedFunctions unused, string query, string functionName)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedFunctions = AllowedFunctions.AllFunctions & ~AllowedFunctions.AllMathFunctions,
            };
            var expectedMessage = string.Format(
                "Function '{0}' is not allowed. " +
                "To allow it, set the 'AllowedFunctions' property on EnableQueryAttribute or QueryValidationSettings.",
                functionName);
            var option = new FilterQueryOption(query, _productContext, queryTranslator: null);

            // Act & Assert
            Assert.Throws<ODataException>(() => _validator.Validate(option, settings), expectedMessage);
        }
开发者ID:xuanvufs,项目名称:WebApi,代码行数:16,代码来源:FilterQueryValidatorTest.cs

示例15: LogicalOperators_CheckArguments_ThrowIfNotAllowed

        public void LogicalOperators_CheckArguments_ThrowIfNotAllowed(string query)
        {
            // Arrange
            var settings = new ODataValidationSettings
            {
                AllowedArithmeticOperators = AllowedArithmeticOperators.All & ~AllowedArithmeticOperators.Add,
            };
            var expectedMessage = string.Format(
                "Arithmetic operator 'Add' is not allowed. " +
                "To allow it, set the 'AllowedArithmeticOperators' property on EnableQueryAttribute or QueryValidationSettings.");
            var option = new FilterQueryOption(query, _productContext, queryTranslator: null);

            // Act & Assert
            Assert.Throws<ODataException>(() => _validator.Validate(option, settings), expectedMessage);
        }
开发者ID:xuanvufs,项目名称:WebApi,代码行数:15,代码来源:FilterQueryValidatorTest.cs


注:本文中的FilterQueryOption类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。