本文整理汇总了C#中ODataValidationSettings类的典型用法代码示例。如果您正苦于以下问题:C# ODataValidationSettings类的具体用法?C# ODataValidationSettings怎么用?C# ODataValidationSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataValidationSettings类属于命名空间,在下文中一共展示了ODataValidationSettings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
/// <summary>
/// Validates a <see cref="CountQueryOption" />.
/// </summary>
/// <param name="countQueryOption">The $count query.</param>
/// <param name="validationSettings">The validation settings.</param>
public virtual void Validate(CountQueryOption countQueryOption, ODataValidationSettings validationSettings)
{
if (countQueryOption == null)
{
throw Error.ArgumentNull("countQueryOption");
}
if (validationSettings == null)
{
throw Error.ArgumentNull("validationSettings");
}
ODataPath path = countQueryOption.Context.Path;
if (path != null && path.Segments.Count > 0)
{
ODataPathSegment lastSegment = path.Segments.Last();
if (lastSegment is CountPathSegment && path.Segments.Count > 1)
{
ValidateCount(path.Segments[path.Segments.Count - 2], countQueryOption.Context.Model);
}
else
{
ValidateCount(lastSegment, countQueryOption.Context.Model);
}
}
}
示例2: Validate
/// <summary>
/// Validates a <see cref="TopQueryOption" />.
/// </summary>
/// <param name="selectExpandQueryOption">The $select and $expand query.</param>
/// <param name="validationSettings">The validation settings.</param>
public virtual void Validate(SelectExpandQueryOption selectExpandQueryOption, ODataValidationSettings validationSettings)
{
if (selectExpandQueryOption == null)
{
throw Error.ArgumentNull("selectExpandQueryOption");
}
if (validationSettings == null)
{
throw Error.ArgumentNull("validationSettings");
}
IEdmModel model = selectExpandQueryOption.Context.Model;
ValidateRestrictions(selectExpandQueryOption.SelectExpandClause, model);
if (validationSettings.MaxExpansionDepth > 0)
{
if (selectExpandQueryOption.LevelsMaxLiteralExpansionDepth > validationSettings.MaxExpansionDepth)
{
throw new ODataException(Error.Format(
SRResources.InvalidExpansionDepthValue,
"LevelsMaxLiteralExpansionDepth",
"MaxExpansionDepth"));
}
ValidateDepth(selectExpandQueryOption.SelectExpandClause, validationSettings.MaxExpansionDepth);
}
}
示例3: ValidateAllNode
/// <summary>
/// Override this method to restrict the 'all' query inside the filter query.
/// </summary>
/// <remarks>
/// This method is intended to be called from method overrides in subclasses. This method also supports unit-testing scenarios and is not intended to be called from user code.
/// Call the Validate method to validate a <see cref="FilterQueryOption"/> instance.
/// </remarks>
/// <param name="allNode"></param>
/// <param name="settings"></param>
public virtual void ValidateAllNode(AllNode allNode, ODataValidationSettings settings)
{
if (allNode == null)
{
throw Error.ArgumentNull("allNode");
}
if (settings == null)
{
throw Error.ArgumentNull("settings");
}
EnterLambda(settings);
try
{
ValidateQueryNode(allNode.Source, settings);
ValidateQueryNode(allNode.Body, settings);
}
finally
{
ExitLambda();
}
}
示例4: Validate
public virtual void Validate(OrderByQueryOption orderByOption, ODataValidationSettings validationSettings)
{
if (orderByOption == null)
{
throw Error.ArgumentNull("orderByOption");
}
if (validationSettings == null)
{
throw Error.ArgumentNull("validationSettings");
}
if (validationSettings.AllowedOrderByProperties.Count > 0)
{
ICollection<OrderByPropertyNode> propertyNodes = orderByOption.PropertyNodes;
foreach (OrderByPropertyNode property in propertyNodes)
{
if (!validationSettings.AllowedOrderByProperties.Contains(property.Property.Name))
{
throw new ODataException(Error.Format(SRResources.NotAllowedOrderByProperty, property.Property.Name, "AllowedOrderByProperties"));
}
}
}
}
示例5: Validate
/// <summary>
/// Validates the specified query options.
/// </summary>
/// <param name="queryOptions">The query options.</param>
/// <param name="validationSettings">The validation settings.</param>
/// <exception cref="ODataException">Thrown if the validation fails.</exception>
internal static void Validate(ODataQueryOptions queryOptions, ODataValidationSettings validationSettings)
{
if (queryOptions.Filter != null)
{
if ((validationSettings.AllowedQueryOptions & AllowedQueryOptions.Filter) != AllowedQueryOptions.Filter)
{
throw new ODataException(Messages.FilterQueryOptionNotSupported);
}
ValidateFunctions(queryOptions.Filter.RawValue, validationSettings);
ValidateStringFunctions(queryOptions.Filter.RawValue, validationSettings);
ValidateDateFunctions(queryOptions.Filter.RawValue, validationSettings);
ValidateMathFunctions(queryOptions.Filter.RawValue, validationSettings);
ValidateLogicalOperators(queryOptions.Filter.RawValue, validationSettings);
ValidateArithmeticOperators(queryOptions.Filter.RawValue, validationSettings);
}
if (queryOptions.RawValues.Expand != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.Expand) != AllowedQueryOptions.Expand)
{
throw new ODataException(Messages.ExpandQueryOptionNotSupported);
}
if (queryOptions.RawValues.Format != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.Format) != AllowedQueryOptions.Format)
{
throw new ODataException(Messages.FormatQueryOptionNotSupported);
}
if (queryOptions.RawValues.InlineCount != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.InlineCount) != AllowedQueryOptions.InlineCount)
{
throw new ODataException(Messages.InlineCountQueryOptionNotSupported);
}
if (queryOptions.RawValues.OrderBy != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.OrderBy) != AllowedQueryOptions.OrderBy)
{
throw new ODataException(Messages.OrderByQueryOptionNotSupported);
}
if (queryOptions.RawValues.Select != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.Select) != AllowedQueryOptions.Select)
{
throw new ODataException(Messages.SelectQueryOptionNotSupported);
}
if (queryOptions.RawValues.Skip != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.Skip) != AllowedQueryOptions.Skip)
{
throw new ODataException(Messages.SkipQueryOptionNotSupported);
}
if (queryOptions.RawValues.Top != null
&& (validationSettings.AllowedQueryOptions & AllowedQueryOptions.Top) != AllowedQueryOptions.Top)
{
throw new ODataException(Messages.TopQueryOptionNotSupported);
}
}
示例6: Validate_NoException_ForAllowedAndSortableUnlimitedProperty_OnEmptyAllowedPropertiesList
public void Validate_NoException_ForAllowedAndSortableUnlimitedProperty_OnEmptyAllowedPropertiesList()
{
// Arrange: empty allowed orderby list
ODataValidationSettings settings = new ODataValidationSettings();
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(new OrderByQueryOption("Name asc", _context), settings));
}
示例7: ValidatePassWhenLimitIsNotReached
public void ValidatePassWhenLimitIsNotReached()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxTop = 10
};
_validator.Validate(new TopQueryOption("9", _context), settings);
}
示例8: Validate_DoesntThrowUnsortableException_ForUnsortableProperty_OnNonEmptyAllowedPropertiesList
public void Validate_DoesntThrowUnsortableException_ForUnsortableProperty_OnNonEmptyAllowedPropertiesList()
{
// Arrange : nonempty allowed orderby list
ODataValidationSettings settings = new ODataValidationSettings();
settings.AllowedOrderByProperties.Add("UnsortableProperty");
// Act & Assert
_validator.Validate(new OrderByQueryOption("UnsortableProperty asc", _context), settings);
}
示例9: Validate_ThrowsUnsortableException_ForUnsortableProperty_OnEmptyAllowedPropertiesList
public void Validate_ThrowsUnsortableException_ForUnsortableProperty_OnEmptyAllowedPropertiesList()
{
// Arrange : empty allowed orderby list
ODataValidationSettings settings = new ODataValidationSettings();
// Act & Assert
Assert.Throws<ODataException>(() => _validator.Validate(new OrderByQueryOption("UnsortableProperty asc", _context), settings),
"The property 'UnsortableProperty' cannot be used in the $orderby query option.");
}
示例10: ValidateThrowsOnUnsortable
public void ValidateThrowsOnUnsortable()
{
ODataValidationSettings settings = new ODataValidationSettings();
settings.AllowedOrderByProperties.Add("UnsortableProperty");
Assert.Throws<ODataException>(() =>
_validator.Validate(new OrderByQueryOption("UnsortableProperty asc", _context), settings),
"The property 'UnsortableProperty' cannot be used in the $orderby query option.");
}
示例11: Validate_DoesntThrowNotSortableException_ForNotSortableProperty_OnNonEmptyAllowedPropertiesList
public void Validate_DoesntThrowNotSortableException_ForNotSortableProperty_OnNonEmptyAllowedPropertiesList(string property)
{
// Arrange : nonempty allowed orderby list
ODataValidationSettings settings = new ODataValidationSettings();
settings.AllowedOrderByProperties.Add(property);
// Act & Assert
_validator.Validate(new OrderByQueryOption(String.Format("{0} asc", property), _context), settings);
}
示例12: FilterQueryValidatorTest
public FilterQueryValidatorTest()
{
_validator = new MyFilterValidator();
_builder = new ODataConventionModelBuilder();
_builder.EntitySet<QueryCompositionCustomer>("Customer");
_model = _builder.GetEdmModel();
_settings = new ODataValidationSettings();
_context = new ODataQueryContext(_model, typeof(QueryCompositionCustomer));
}
示例13: ValidatePassWhenLimitIsNotReached
public void ValidatePassWhenLimitIsNotReached()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxSkip = 10
};
Assert.DoesNotThrow(() => _validator.Validate(new SkipQueryOption("9", _context), settings));
}
示例14: ValidateAllowsOrderByIt_IfExplicitlySpecified
public void ValidateAllowsOrderByIt_IfExplicitlySpecified()
{
// Arrange
OrderByQueryOption option = new OrderByQueryOption("$it", new ODataQueryContext(EdmCoreModel.Instance, typeof(int)), queryTranslator: null);
ODataValidationSettings settings = new ODataValidationSettings { AllowedOrderByProperties = { "$it" } };
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(option, settings));
}
示例15: ValidateAllowsOrderByIt
public void ValidateAllowsOrderByIt()
{
// Arrange
OrderByQueryOption option = new OrderByQueryOption("$it", _context);
ODataValidationSettings settings = new ODataValidationSettings();
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(option, settings));
}