本文整理汇总了C#中ODataValidationSettings类的典型用法代码示例。如果您正苦于以下问题:C# ODataValidationSettings类的具体用法?C# ODataValidationSettings怎么用?C# ODataValidationSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ODataValidationSettings类属于命名空间,在下文中一共展示了ODataValidationSettings类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:33,代码来源:CountQueryValidator.cs
示例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);
}
}
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:33,代码来源:SelectExpandQueryValidator.cs
示例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();
}
}
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:34,代码来源:FilterQueryValidator.cs
示例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"));
}
}
}
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:25,代码来源:OrderByQueryValidator.cs
示例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);
}
}
开发者ID:JulioGold,项目名称:Net.Http.WebApi.OData,代码行数:65,代码来源:ODataQueryOptionsValidator.cs
示例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));
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:8,代码来源:OrderByQueryValidatorTest.cs
示例7: ValidatePassWhenLimitIsNotReached
public void ValidatePassWhenLimitIsNotReached()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxTop = 10
};
_validator.Validate(new TopQueryOption("9", _context), settings);
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:9,代码来源:TopQueryValidatorTest.cs
示例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);
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例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.");
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例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.");
}
开发者ID:modulexcite,项目名称:aspnetwebstack-1,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例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);
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例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));
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:9,代码来源:FilterQueryValidatorTest.cs
示例13: ValidatePassWhenLimitIsNotReached
public void ValidatePassWhenLimitIsNotReached()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxSkip = 10
};
Assert.DoesNotThrow(() => _validator.Validate(new SkipQueryOption("9", _context), settings));
}
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:9,代码来源:SkipQueryValidatorTest.cs
示例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));
}
开发者ID:xuanvufs,项目名称:WebApi,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例15: ValidateAllowsOrderByIt
public void ValidateAllowsOrderByIt()
{
// Arrange
OrderByQueryOption option = new OrderByQueryOption("$it", _context);
ODataValidationSettings settings = new ODataValidationSettings();
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(option, settings));
}
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例16: ValidateAllowsOrderByIt
public void ValidateAllowsOrderByIt()
{
// Arrange
OrderByQueryOption option = new OrderByQueryOption("$it", new ODataQueryContext(EdmCoreModel.Instance, typeof(int)));
ODataValidationSettings settings = new ODataValidationSettings();
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(option, settings));
}
开发者ID:sujiantao,项目名称:aspnetwebstack,代码行数:9,代码来源:OrderByQueryValidatorTest.cs
示例17: ValidatePassWhenLimitIsReached
public void ValidatePassWhenLimitIsReached()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxSkip = 10
};
_validator.Validate(new SkipQueryOption("10", _context), settings);
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:9,代码来源:SkipQueryValidatorTest.cs
示例18: ValidateThrowsWhenLimitIsExceeded
public void ValidateThrowsWhenLimitIsExceeded()
{
ODataValidationSettings settings = new ODataValidationSettings()
{
MaxSkip = 10
};
Assert.Throws<ODataException>(() =>
_validator.Validate(new SkipQueryOption("11", _context), settings));
}
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:10,代码来源:SkipQueryValidatorTest.cs
示例19: Validate_ThrowsNotAllowedException_ForNotAllowedAndSortableLimitedProperty
public void Validate_ThrowsNotAllowedException_ForNotAllowedAndSortableLimitedProperty()
{
// Arrange
ODataValidationSettings settings = new ODataValidationSettings();
settings.AllowedOrderByProperties.Add("Name");
// Act & Assert
Assert.Throws<ODataException>(() => _validator.Validate(new OrderByQueryOption("UnsortableProperty asc", _context), settings),
"Order by 'UnsortableProperty' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on EnableQueryAttribute or QueryValidationSettings.");
}
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:10,代码来源:OrderByQueryValidatorTest.cs
示例20: ValidateWillAllowId
public void ValidateWillAllowId()
{
// Arrange
OrderByQueryOption option = new OrderByQueryOption("Id", _context);
ODataValidationSettings settings = new ODataValidationSettings();
settings.AllowedOrderByProperties.Add("Id");
// Act & Assert
Assert.DoesNotThrow(() => _validator.Validate(option, settings));
}
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:10,代码来源:OrderByQueryValidatorTest.cs
注:本文中的ODataValidationSettings类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论