/// <summary>
        /// Allows the $orderby query option.
        /// </summary>
        /// <typeparam name="TModel">The type of <see cref="ICommonModel">model</see>.</typeparam>
        /// <param name="builder">The extended convention builder.</param>
        /// <param name="properties">The <see cref="IEnumerable{T}">sequence</see> of property names that can appear in the $orderby query option.
        /// An empty sequence indicates that any property can appear in the $orderby query option.</param>
        /// <returns>The original <paramref name="builder"/>.</returns>
        public static ODataActionQueryOptionsConventionBuilder <TModel> AllowOrderBy <TModel>(
            this ODataActionQueryOptionsConventionBuilder <TModel> builder, IEnumerable <string> properties)
        {
            Arg.NotNull(builder, nameof(builder));
            Arg.NotNull(properties, nameof(properties));

            return(builder.AllowOrderBy(default, properties));
            internal ActionBuilderMapping(MethodInfo method, ODataActionQueryOptionsConventionBuilder builder)
            {
                Contract.Requires(method != null);
                Contract.Requires(builder != null);

                Method  = method;
                Builder = builder;
            }
Esempio n. 3
0
        /// <summary>
        /// Allows the $orderby query option.
        /// </summary>
        /// <typeparam name="TModel">The type of <see cref="ICommonModel">model</see>.</typeparam>
        /// <param name="builder">The extended convention builder.</param>
        /// <param name="properties">The <see cref="IEnumerable{T}">sequence</see> of property names that can appear in the $orderby query option.
        /// An empty sequence indicates that any property can appear in the $orderby query option.</param>
        /// <returns>The original <paramref name="builder"/>.</returns>
        public static ODataActionQueryOptionsConventionBuilder <TModel> AllowOrderBy <TModel>(
            this ODataActionQueryOptionsConventionBuilder <TModel> builder, IEnumerable <string> properties) where TModel : notnull
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AllowOrderBy(default, properties));
        /// <summary>
        /// Allows the $orderby query option.
        /// </summary>
        /// <typeparam name="TModel">The type of <see cref="ICommonModel">model</see>.</typeparam>
        /// <param name="builder">The extended convention builder.</param>
        /// <param name="maxNodeCount">The maximum number of expressions in the $orderby query option or zero to indicate the default.</param>
        /// <param name="properties">The array of property names that can appear in the $orderby query option.
        /// An empty array indicates that any property can appear in the $orderby query option.</param>
        /// <returns>The original <paramref name="builder"/>.</returns>
        public static ODataActionQueryOptionsConventionBuilder <TModel> AllowOrderBy <TModel>(
            this ODataActionQueryOptionsConventionBuilder <TModel> builder, int maxNodeCount, params string[] properties)
        {
            Arg.NotNull(builder, nameof(builder));
            Arg.NotNull(properties, nameof(properties));
            Arg.GreaterThanOrEqualTo(maxNodeCount, 0, nameof(maxNodeCount));

            return(builder.AllowOrderBy(maxNodeCount, properties.AsEnumerable()));
        }
        /// <summary>
        /// Allows the $orderby query option.
        /// </summary>
        /// <typeparam name="TController">The type of <see cref="IHttpController">controller</see>.</typeparam>
        /// <param name="builder">The extended convention builder.</param>
        /// <param name="properties">The <see cref="IEnumerable{T}">sequence</see> of property names that can appear in the $orderby query option.
        /// An empty sequence indicates that any property can appear in the $orderby query option.</param>
        /// <returns>The original <paramref name="builder"/>.</returns>
        public static ODataActionQueryOptionsConventionBuilder <TController> AllowOrderBy <TController>(
            this ODataActionQueryOptionsConventionBuilder <TController> builder,
            IEnumerable <string> properties)
            where TController : IHttpController
        {
            Arg.NotNull(builder, nameof(builder));
            Arg.NotNull(properties, nameof(properties));

            return(builder.AllowOrderBy(default, properties));
Esempio n. 6
0
        /// <summary>
        /// Allows the $orderby query option.
        /// </summary>
        /// <typeparam name="TModel">The type of <see cref="ICommonModel">model</see>.</typeparam>
        /// <param name="builder">The extended convention builder.</param>
        /// <param name="maxNodeCount">The maximum number of expressions in the $orderby query option or zero to indicate the default.</param>
        /// <param name="properties">The array of property names that can appear in the $orderby query option.
        /// An empty array indicates that any property can appear in the $orderby query option.</param>
        /// <returns>The original <paramref name="builder"/>.</returns>
        public static ODataActionQueryOptionsConventionBuilder <TModel> AllowOrderBy <TModel>(
            this ODataActionQueryOptionsConventionBuilder <TModel> builder, int maxNodeCount, params string[] properties) where TModel : notnull
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.AllowOrderBy(maxNodeCount, properties.AsEnumerable()));
        }
        /// <summary>
        /// Attempts to retrieve the controller action convention builder for the specified method.
        /// </summary>
        /// <param name="actionMethod">The controller action method to get the convention builder for.</param>
        /// <param name="actionBuilder">The <see cref="ODataActionQueryOptionsConventionBuilder{T}">controller action convention builder</see> or <c>null</c>.</param>
        /// <returns>True if the <paramref name="actionBuilder">action builder</paramref> is successfully retrieved; otherwise, false.</returns>
        public virtual bool TryGetValue(MethodInfo actionMethod, out ODataActionQueryOptionsConventionBuilder <T> actionBuilder)
        {
            actionBuilder = null;

            if (actionMethod == null)
            {
                return(false);
            }

            var mapping = actionBuilderMappings.FirstOrDefault(m => m.Method == actionMethod);

            return((actionBuilder = mapping?.Builder) != null);
        }
Esempio n. 8
0
        public void action_should_call_action_on_controller_builder()
        {
            // arrange
            var controllerBuilder = new Mock <ODataControllerQueryOptionsConventionBuilder <TestController> >();
            var actionBuilder     = new ODataActionQueryOptionsConventionBuilder <TestController>(controllerBuilder.Object);
            var method            = typeof(TestController).GetMethod(nameof(TestController.Get));

            controllerBuilder.Setup(cb => cb.Action(It.IsAny <MethodInfo>()));

            // act
            actionBuilder.Action(method);

            // assert
            controllerBuilder.Verify(cb => cb.Action(method), Once());
        }