/// <summary> /// Initializes a new instance of the <see cref="ODataValidationSettingsConvention"/> class. /// </summary> /// <param name="validationSettings">The <see cref="ODataValidationSettings">validation settings</see> the convention is based on.</param> /// <param name="settings">The <see cref="ODataQueryOptionSettings">settings</see> used by the convention.</param> public ODataValidationSettingsConvention(ODataValidationSettings validationSettings, ODataQueryOptionSettings settings) { Arg.NotNull(validationSettings, nameof(validationSettings)); ValidationSettings = validationSettings; Settings = settings; }
public void apply_should_apply_configured_conventions() { // arrange var controller = new HttpControllerDescriptor(new HttpConfiguration(), "Stub", typeof(StubController)); var action = new ReflectedHttpActionDescriptor(controller, typeof(StubController).GetMethod(nameof(StubController.Get))); var description = new VersionedApiDescription() { ActionDescriptor = action, HttpMethod = HttpMethod.Get, ResponseDescription = new ResponseDescription() { ResponseType = typeof(object), }, Properties = { [typeof(IEdmModel)] = new EdmModel(), } }; var builder = new ODataQueryOptionsConventionBuilder(); var settings = new ODataQueryOptionSettings() { DescriptionProvider = builder.DescriptionProvider }; var convention = new Mock <IODataQueryOptionsConvention>(); convention.Setup(c => c.ApplyTo(It.IsAny <ApiDescription>())); builder.Add(convention.Object); // act builder.ApplyTo(new[] { description }, settings); // assert convention.Verify(c => c.ApplyTo(description), Once()); }
public void apply_should_apply_configured_conventions() { // arrange var description = new ApiDescription() { ActionDescriptor = new ControllerActionDescriptor() { ControllerTypeInfo = typeof(StubController).GetTypeInfo(), MethodInfo = typeof(StubController).GetTypeInfo().GetRuntimeMethod(nameof(StubController.Get), Type.EmptyTypes), }, HttpMethod = "GET", }; var builder = new ODataQueryOptionsConventionBuilder(); var settings = new ODataQueryOptionSettings() { DescriptionProvider = builder.DescriptionProvider, DefaultQuerySettings = new DefaultQuerySettings(), ModelMetadataProvider = Mock.Of <IModelMetadataProvider>(), }; var convention = new Mock <IODataQueryOptionsConvention>(); convention.Setup(c => c.ApplyTo(It.IsAny <ApiDescription>())); builder.Add(convention.Object); // act builder.ApplyTo(new[] { description }, settings); // assert convention.Verify(c => c.ApplyTo(description), Once()); }
internal ODataControllerQueryOptionConvention( ODataActionQueryOptionConventionLookup lookup, ODataQueryOptionSettings settings) { this.lookup = lookup; this.settings = settings; }
internal ODataControllerQueryOptionConvention( ODataActionQueryOptionConventionLookup lookup, ODataQueryOptionSettings settings) { Contract.Requires(lookup != null); Contract.Requires(lookup != null); Contract.Requires(settings != null); this.lookup = lookup; this.settings = settings; }
bool Lookup(MethodInfo action, ODataQueryOptionSettings settings, out IODataQueryOptionsConvention?convention) { if (ActionBuilders.TryGetValue(action, out var builder)) { convention = builder !.Build(settings); return(true); } convention = default; return(false); }
static IODataQueryOptionsConvention ImplicitActionConvention(ODataQueryOptionSettings settings) { var validationSettings = new ODataValidationSettings() { AllowedArithmeticOperators = AllowedArithmeticOperators.None, AllowedFunctions = AllowedFunctions.None, AllowedLogicalOperators = AllowedLogicalOperators.None, AllowedQueryOptions = AllowedQueryOptions.None, }; return(new ODataValidationSettingsConvention(validationSettings, settings)); }
static IODataQueryOptionsConvention ImplicitActionConvention(ODataQueryOptionSettings settings) { Contract.Requires(settings != null); Contract.Ensures(Contract.Result <IODataQueryOptionsConvention>() != null); var validationSettings = new ODataValidationSettings() { AllowedArithmeticOperators = AllowedArithmeticOperators.None, AllowedFunctions = AllowedFunctions.None, AllowedLogicalOperators = AllowedLogicalOperators.None, AllowedQueryOptions = AllowedQueryOptions.None, }; return(new ODataValidationSettingsConvention(validationSettings, settings)); }
/// <summary> /// Applies the defined OData query option conventions to the specified API description. /// </summary> /// <param name="apiDescriptions">The <see cref="IEnumerable{T}">sequence</see> of <see cref="ApiDescription">API descriptions</see> /// to apply configured conventions to.</param> /// <param name="queryOptionSettings">The <see cref="ODataQueryOptionSettings">settings</see> used to apply OData query option conventions.</param> public virtual void ApplyTo(IEnumerable <ApiDescription> apiDescriptions, ODataQueryOptionSettings queryOptionSettings) { if (apiDescriptions == null) { throw new ArgumentNullException(nameof(apiDescriptions)); } var conventions = new Dictionary <TypeInfo, IODataQueryOptionsConvention>(); foreach (var description in apiDescriptions) { var controller = GetController(description); if (!conventions.TryGetValue(controller, out var convention)) { if (!controller.IsODataController() && !IsODataLike(description)) { continue; } if (!ConventionBuilders.TryGetValue(controller, out var builder)) { builder = new ODataControllerQueryOptionsConventionBuilder(controller); } convention = builder.Build(queryOptionSettings); conventions.Add(controller, convention); } convention.ApplyTo(description); for (var i = 0; i < Conventions.Count; i++) { Conventions[i].ApplyTo(description); } } }
/// <inheritdoc /> public virtual IODataQueryOptionsConvention Build(ODataQueryOptionSettings settings) => new ODataControllerQueryOptionConvention(Lookup, settings);
/// <inheritdoc /> public virtual IODataQueryOptionsConvention Build(ODataQueryOptionSettings settings) => new ODataValidationSettingsConvention(ValidationSettings, settings);
/// <summary> /// Initializes a new instance of the <see cref="ODataValidationSettingsConvention"/> class. /// </summary> /// <param name="validationSettings">The <see cref="ODataValidationSettings">validation settings</see> the convention is based on.</param> /// <param name="settings">The <see cref="ODataQueryOptionSettings">settings</see> used by the convention.</param> public ODataValidationSettingsConvention(ODataValidationSettings validationSettings, ODataQueryOptionSettings settings) { ValidationSettings = validationSettings; Settings = settings; }