Exemplo n.º 1
0
        public void A220_GetByArgs_All_Paging()
        {
            using var agentTester = AgentTester.CreateWaf <Startup>();

            var r = agentTester.Test <EmployeeAgent, EmployeeBaseCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByArgsAsync(new EmployeeArgs {
                IsIncludeTerminated = true
            }, PagingArgs.CreateSkipAndTake(1, 2)));

            var v = r.Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "Jones", "Smith" }, v.Result.Select(x => x.LastName).ToArray());

            // Query again with etag and ensure not modified.
            agentTester.Test <EmployeeAgent, EmployeeBaseCollectionResult>()
            .ExpectStatusCode(HttpStatusCode.NotModified)
            .Run(a => a.GetByArgsAsync(new EmployeeArgs {
                IsIncludeTerminated = true
            }, PagingArgs.CreateSkipAndTake(1, 2), new WebApiRequestOptions {
                ETag = r.Response !.Headers !.ETag !.Tag
            }));
Exemplo n.º 2
0
        public void C110_GetAll_Paging()
        {
            var pcr = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run((a) => a.Agent.GetAllAsync(PagingArgs.CreateSkipAndTake(1, 2)));

            // Check only 2 are returned in the sorted order.
            Assert.AreEqual(2, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Jones", "Smith", }, pcr.Value.Result.Select(x => x.LastName).ToArray());
        }
Exemplo n.º 3
0
        public void C120_GetByArgs_All_Paging()
        {
            var pcr = AgentTester.Create <RobotAgent, RobotCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run((a) => a.Agent.GetByArgsAsync(new RobotArgs(), PagingArgs.CreateSkipAndTake(1, 2)));

            // Check only 2 are returned in the sorted order.
            Assert.AreEqual(2, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "223456", "A45768", }, pcr.Value.Result.Select(x => x.SerialNo).ToArray());
        }
        public void A220_GetByEmployeeId_Last()
        {
            var v = AgentTester.Test <PerformanceReviewAgent, PerformanceReviewCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByEmployeeIdAsync(2.ToGuid(), PagingArgs.CreateSkipAndTake(0, 1))).Value !;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(1, v.Result.Count);
            Assert.AreEqual(new string[] { "Work quality low." }, v.Result.Select(x => x.Notes).ToArray());
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void A210_GetByArgs_All_Paging()
        {
            var v = AgentTester.Test <EmployeeAgent, EmployeeBaseCollectionResult>()
                    .ExpectStatusCode(HttpStatusCode.OK)
                    .Run(a => a.GetByArgsAsync(new EmployeeArgs {
                IsIncludeTerminated = true
            }, PagingArgs.CreateSkipAndTake(1, 2))).Value;

            Assert.IsNotNull(v);
            Assert.IsNotNull(v.Result);
            Assert.AreEqual(2, v.Result.Count);
            Assert.AreEqual(new string[] { "Jones", "Smith" }, v.Result.Select(x => x.LastName).ToArray());
        }
Exemplo n.º 7
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.º 8
0
        public void C120_GetAll_PagingAndFieldFiltering()
        {
            var pa = PagingArgs.CreateSkipAndTake(1, 2);
            var ro = new WebApiRequestOptions().Include("lastName", "firstName");

            var pcr = AgentTester.Create <PersonAgent, PersonCollectionResult>()
                      .ExpectStatusCode(HttpStatusCode.OK)
                      .Run((a) => a.Agent.GetAllAsync(pa, ro));

            // Check only 2 are returned in the sorted order.
            Assert.AreEqual(2, pcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Jones", "Smith", }, pcr.Value.Result.Select(x => x.LastName).ToArray());
            Assert.IsFalse(pcr.Value.Result.Any(x => x.Id != Guid.Empty));
        }
Exemplo n.º 9
0
        public void D310_GetDetailByArgs_LastName()
        {
            var args = new PersonArgs {
                LastName = "sm*"
            };
            var pdcr = AgentTester.Create <PersonAgent, PersonDetailCollectionResult>()
                       .ExpectStatusCode(HttpStatusCode.OK)
                       .Run((a) => a.Agent.GetDetailByArgsAsync(args, PagingArgs.CreateSkipAndTake(0, 2, true)));

            Assert.AreEqual(2, pdcr?.Value?.Result?.Count);
            Assert.AreEqual(new string[] { "Smith", "Smithers" }, pdcr.Value.Result.Select(x => x.LastName).ToArray());
            Assert.AreEqual(2, pdcr.Value.Result[0].History.Count);
            Assert.AreEqual(2, pdcr.Value.Result[1].History.Count);

            Assert.AreEqual(2, pdcr.Value.Paging.TotalCount);
        }