Exemplo n.º 1
0
        public void B330_GetAccounts_Page3()
        {
            var v = AgentTester.Create <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAccountsAsync(null, PagingArgs.CreatePageAndSize(3, 2))).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(0, v.Result.Count);
        }
Exemplo n.º 2
0
        public void B320_GetAccounts_Page2()
        {
            var v = AgentTester.Create <AccountAgent, AccountCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run((a) => a.Agent.GetAccountsAsync(null, PagingArgs.CreatePageAndSize(2, 2))).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(1, v.Result.Count);
            Assert.AreEqual(new string[] { "45678901" }, v.Result.Select(x => x.Id).ToArray());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates the <see cref="PagingArgs"/> from the query string.
        /// </summary>
        /// <param name="controller">The <see cref="ControllerBase"/> that has the request url.</param>
        /// <param name="useExectionContext">Indicates whether to use the <see cref="ExecutionContext"/> value where there is already a current value (see <see cref="ExecutionContext.PagingArgs"/>).</param>
        /// <param name="overrideExecutionContext">Indicates whether to update the <see cref="ExecutionContext"/> value where there is no current value.</param>
        /// <returns>The <see cref="PagingArgs"/>.</returns>
        public static PagingArgs CreatePagingArgs(this ControllerBase controller, bool useExectionContext = false, bool overrideExecutionContext = true)
        {
            if (useExectionContext && ExecutionContext.HasCurrent && ExecutionContext.Current.PagingArgs != null)
            {
                return(ExecutionContext.Current.PagingArgs);
            }

            PagingArgs pa = null;
            var        q  = controller.HttpContext.Request.Query;

            if (q == null || q.Count == 0)
            {
                pa = new PagingArgs();
            }
            else
            {
                long?skip = ParseLongValue(GetNamedQueryString(controller, PagingArgsSkipQueryStringNames));
                long?take = ParseLongValue(GetNamedQueryString(controller, PagingArgsTakeQueryStringNames));
                long?page = skip.HasValue ? null : ParseLongValue(GetNamedQueryString(controller, PagingArgsPageQueryStringNames));

                if (skip == null && page == null)
                {
                    pa = (take.HasValue) ? PagingArgs.CreateSkipAndTake(0, take) : new PagingArgs();
                }
                else
                {
                    pa = (skip.HasValue) ? PagingArgs.CreateSkipAndTake(skip.Value, take) : PagingArgs.CreatePageAndSize(page.Value, take);
                }

                pa.IsGetCount = ParseBoolValue(GetNamedQueryString(controller, PagingArgsCountQueryStringNames));

                var fields = GetNamedQueryString(controller, IncludeFieldsStringNames);
                if (!string.IsNullOrEmpty(fields))
                {
                    pa.IncludeFields.AddRange(fields.Split(',', StringSplitOptions.RemoveEmptyEntries));
                }

                fields = GetNamedQueryString(controller, ExcludeFieldsStringNames);
                if (!string.IsNullOrEmpty(fields))
                {
                    pa.ExcludeFields.AddRange(fields.Split(',', StringSplitOptions.RemoveEmptyEntries));
                }
            }

            if (overrideExecutionContext && ExecutionContext.HasCurrent && ExecutionContext.Current.PagingArgs == null)
            {
                ExecutionContext.Current.PagingArgs = pa;
            }

            return(pa);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the <see cref="PagingArgs"/> from the query string.
        /// </summary>
        /// <param name="controller">The <see cref="ControllerBase"/> that has the request url.</param>
        /// <returns>The <see cref="PagingArgs"/>.</returns>
        /// <remarks>Will return the <see cref="ExecutionContext"/> <see cref="ExecutionContext.PagingArgs"/> where already set; otherwise, will update it once value inferred.</remarks>
        public static PagingArgs CreatePagingArgs(this ControllerBase controller)
        {
            Check.NotNull(controller, nameof(controller));
            if (ExecutionContext.HasCurrent && ExecutionContext.Current.PagingArgs != null)
            {
                return(ExecutionContext.Current.PagingArgs);
            }

#pragma warning disable CA1062 // Validate arguments of public methods; see earlier Check.
            var q = controller.HttpContext?.Request?.Query;
#pragma warning restore CA1062
            PagingArgs pa;

            if (q == null || q.Count == 0)
            {
                pa = new PagingArgs();
            }
            else
            {
                long?skip = ParseLongValue(GetNamedQueryString(controller, PagingArgsSkipQueryStringNames));
                long?take = ParseLongValue(GetNamedQueryString(controller, PagingArgsTakeQueryStringNames));
                long?page = skip.HasValue ? null : ParseLongValue(GetNamedQueryString(controller, PagingArgsPageQueryStringNames));

                if (skip == null && page == null)
                {
                    pa = (take.HasValue) ? PagingArgs.CreateSkipAndTake(0, take) : new PagingArgs();
                }
                else
                {
                    pa = (skip.HasValue) ? PagingArgs.CreateSkipAndTake(skip.Value, take) : PagingArgs.CreatePageAndSize(page.Value, take);
                }

                pa.IsGetCount = ParseBoolValue(GetNamedQueryString(controller, PagingArgsCountQueryStringNames));

                var fields = GetNamedQueryString(controller, IncludeFieldsQueryStringNames);
                if (!string.IsNullOrEmpty(fields))
                {
                    pa.IncludeFields.AddRange(fields.Split(',', StringSplitOptions.RemoveEmptyEntries));
                }

                fields = GetNamedQueryString(controller, ExcludeFieldsQueryStringNames);
                if (!string.IsNullOrEmpty(fields))
                {
                    pa.ExcludeFields.AddRange(fields.Split(',', StringSplitOptions.RemoveEmptyEntries));
                }
            }

            if (ExecutionContext.HasCurrent && ExecutionContext.Current.PagingArgs == null)
            {
                ExecutionContext.Current.PagingArgs = pa;
            }

            return(pa);
        }