本文整理汇总了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);
}
示例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);
}
示例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
}
示例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));
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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));
}
示例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
}
示例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.");
}
示例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.");
}
示例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.");
}
示例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);
}
示例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);
}