public async void HRBorderControllerOnGetAllWithValidPagingInExpectItemsAndCodeStatus200()
        {
            List <String> list = new List <String>();

            for (int i = 0; i < 300; i++)
            {
                list.Add(i.ToString());
            }
            //CoreBordersServiceStub service = new CoreBordersServiceStub(list);
            PagingParameterInModel validModel = new PagingParameterInModel()
            {
                PageNumber = 1, PageSize = 50
            };
            HRCommonForkerUtilsStub forkerUtil = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRBordersControllersForker forker = new HRBordersControllersForker(forkerUtil);

            using (Task <(int, PagingParameterOutModel <HRBorder>)> resultService = forker.GetFromPagingAsync(
                       validModel,
                       null,
                       new CoreBordersServiceStub(list),
                       50
                       ))
            {
                await resultService;
                Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK);
                Assert.True(resultService.Result.Item2 != null);
            }
        }
        public void PaginateEmptyListsReturnSinglePagePaginationWithEmptyResult()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageNumber = 0;
            model.PageSize   = 20;
            List <String> paginerItems = new List <String>();
            PagingParameterOutModel <String> retour = paginer.GetPaginationFromFullList(model, paginerItems);

            Assert.NotNull(retour);
            Assert.True(retour.TotalItemsCount == 0);
            Assert.True(retour.TotalPages == 1);
            Assert.True(retour.PageSize == 20);
            Assert.NotNull(retour.PageItems);
            int itemsCount = 0;
            IEnumerator <String> enumerator = retour.PageItems.GetEnumerator();

            while (enumerator.MoveNext())
            {
                itemsCount++;
            }
            Assert.True(itemsCount == 0);
            Assert.False(retour.HasPreviousPage);
            Assert.False(retour.HasNextPage);
            Assert.True(retour.CurrentPage == 0);
        }
        public async void HRCountriesOnGetFromPagingWithModelPageSizeGreaterThanMaxSizeExpectCodeStatus413PayloadTooLarge()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 51
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException = true
            };

            service.ExceptionToThrow = new IndexOutOfRangeException();
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status413PayloadTooLarge);
            }
        }
        public async void HRCountriesOnGetFromPagingWithCanOrderReturnoingFalseExpectStatus400BadRequest()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 50
            };
            HRSortingParamModel sort = new HRSortingParamModel()
            {
                OrderBy = "FIELD1;ASC"
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException   = true,
                ExceptionToThrow = new IndexOutOfRangeException()
            };
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = false
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       sort,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status400BadRequest);
            }
        }
        public void PaginateMultiplePageOnLastPageExpectOutModelIsConsistent()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageSize   = 50;
            model.PageNumber = 4;
            PagingParameterOutModel <String> result = paginer.GetPaginationFromFullList(model, CreateItems(210));

            Assert.NotNull(result);
            Assert.False(result.HasNextPage);
            Assert.True(result.HasPreviousPage);
            Assert.True(result.TotalItemsCount == 210);
            Assert.True(result.CurrentPage == 4);
            IEnumerable <String> items = result.PageItems;

            Assert.NotNull(items);
            Assert.NotEmpty(items);
            IEnumerator <String> enumerator = items.GetEnumerator();
            int    i = 200;
            String valueExceptedi = String.Empty;

            while (enumerator.MoveNext())
            {
                valueExceptedi = "Items number " + i.ToString();
                Assert.Equal(valueExceptedi, enumerator.Current);
                i++;
            }
            Assert.True(i == 210);
        }
Exemplo n.º 6
0
        public async void HRCountriesController_On_GetAll_With_Invalid_PagingIn_Expect_Status416_RequestedRangeNotSatisfiable()
        {
            List <String> list = new List <String>()
            {
                "FR",
                "US"
            };

            PagingParameterInModel invalidModel = new PagingParameterInModel()
            {
                PageNumber = 2, PageSize = 50
            };
            IHRCommonForkerUtils util = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(util);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> resultService = forker.GetFromPagingAsync(
                       invalidModel,
                       null,
                       new CoreCountriesServiceStub(list)
            {
                ThrowException = true, ExceptionToThrow = new IndexOutOfRangeException()
            },
                       50))
            {
                await resultService;
                Assert.True(resultService.Result.Item1 == StatusCodes.Status416RequestedRangeNotSatisfiable);
                Assert.True(resultService.Result.Item2 == null);
            }
        }
        public async void HRCountriesOnGetFromPagingWithServiceThrowingIndexOutOfRangeExceptionExpectStatus500InternalServerError()
        {
            PagingParameterInModel   model   = new PagingParameterInModel();
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(null)
            {
                ThrowException   = true,
                ExceptionToThrow = new IndexOutOfRangeException()
            };

            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status416RequestedRangeNotSatisfiable);
            }
        }
        public void ValidatePaginationInWithEnumerableNullThrowArgumentNullException()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            Assert.Throws <ArgumentNullException>(() => paginer.IsValid(model, null));
        }
Exemplo n.º 9
0
        public async void HRCountriesController_On_GetAll_With_Valid_PagingIn_Expect_Items_And_Code_Status200()
        {
            List <String> list = new List <String>()
            {
                "FR",
                "US"
            };
            PagingParameterInModel invalidModel = new PagingParameterInModel()
            {
                PageNumber = 1, PageSize = 50
            };
            IHRCommonForkerUtils util = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(util);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> resultService = forker.GetFromPagingAsync(
                       invalidModel,
                       null,
                       new CoreCountriesServiceStub(list),
                       50
                       ))
            {
                await resultService;
                Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK);
            }
        }
Exemplo n.º 10
0
        public async void HRCountriesController_On_GetAll_With_Exception_Thrown_By_Service_Expect_Status500_InternalServerError()
        {
            List <String> list = new List <String>()
            {
                "FR",
                "US"
            };

            PagingParameterInModel invalidModel = new PagingParameterInModel()
            {
                PageNumber = 2, PageSize = 50
            };
            IHRCommonForkerUtils util = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(util);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> resultService = forker.GetFromPagingAsync(
                       invalidModel,
                       null,
                       new CoreCountriesServiceStub(list)
            {
                ThrowException = true
            },
                       50
                       ))
            {
                await resultService;
                Assert.True(resultService.Result.Item1 == StatusCodes.Status500InternalServerError);
                Assert.True(resultService.Result.Item2 == null);
            }
        }
Exemplo n.º 11
0
        public async void HRBorderForkerOnGetFromPagingWithServiceThrowingExceptionExpectStatus500InternalServerError()
        {
            PagingParameterInModel model   = new PagingParameterInModel();
            CoreBordersServiceStub service = new CoreBordersServiceStub(null)
            {
                ThrowException = true
            };

            service.ExceptionToThrow = new Exception();
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRBordersControllersForker forker = new HRBordersControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRBorder>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status500InternalServerError);
            }
        }
        public async void HRCountriesControllerOnGetAllWithValidPagingInExpectItemsAndCodeStatus200()
        {
            List <MongoDB.Bson.ObjectId> list = new List <MongoDB.Bson.ObjectId>();

            for (int i = 0; i < 300; i++)
            {
                list.Add(new MongoDB.Bson.ObjectId("507f191e810c19729de860ea"));
            }
            CoreCountriesServiceStub service      = new CoreCountriesServiceStub(list);
            HRCountriesController    ctrl         = new HRCountriesController(service, null);
            PagingParameterInModel   invalidModel = new PagingParameterInModel()
            {
                PageNumber = 1, PageSize = 100
            };
            Task <(int, PagingParameterOutModel <HRCountry>)> resultService = ctrl.GetFromPaging(invalidModel, null);
            await resultService;

            Assert.True(resultService.Result.Item1 == StatusCodes.Status200OK);
            Assert.True(resultService.Result.Item2 != null);
            Assert.True(resultService.Result.Item2.HasNextPage);
            Assert.True(resultService.Result.Item2.HasPreviousPage);
            Assert.True(resultService.Result.Item2.TotalItemsCount == 300);
            int j = 100;

            foreach (HRCountry iterator in resultService.Result.Item2.PageItems)
            {
                j++;
            }
            Assert.True(j == 200);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Get Paginated items.
        /// </summary>
        /// <param name="pageModel">the PagingParameterInModel. Must not be null.</param>
        /// <param name="orderBy">an optionnal orderByClause.</param>
        /// <returns>The corresponding borders paginated an optionnaly</returns>
        public async Task <PagingParameterOutModel <HRBorder> > GetBordersAsync(PagingParameterInModel pageModel, HRSortingParamModel orderBy = null)
        {
            PagingParameterOutModel <HRBorder> retour = null;

            if (_workflow == null)
            {
                if (_logger != null)
                {
                    _logger.LogError("_workflow is null in HRCoreBordersServices");
                }
                throw new MemberAccessException();
            }
            if (pageModel == null)
            {
                if (_logger != null)
                {
                    _logger.LogError("pageModel is null in HRCoreBordersServices : GetBordersAsync");
                }
                throw new ArgumentNullException();
            }
            using (Task <PagingParameterOutModel <HRBorder> > retourTask = _workflow.GetQueryResultsAsync(pageModel, orderBy))
            {
                await retourTask;
                retour = retourTask.Result;
            }
            return(retour);
        }
        public async void HRCountriesOnGetFromPagingWithServiceNormalResultExpectCode200()
        {
            PagingParameterInModel model = new PagingParameterInModel()
            {
                PageNumber = 0,
                PageSize   = 10
            };
            CoreCountriesServiceStub service = new CoreCountriesServiceStub(new System.Collections.Generic.List <string>()
            {
                "XX"
            })
            {
                ThrowException = false
            };
            HRCommonForkerUtilsStub utilStub = new HRCommonForkerUtilsStub()
            {
                CanOrderReturn = true
            };
            HRCountriesControllersForker forker = new HRCountriesControllersForker(utilStub);

            using (Task <(int, PagingParameterOutModel <HRCountry>)> forkerTask = forker.GetFromPagingAsync(
                       model,
                       null,
                       service,
                       50
                       ))
            {
                await forkerTask;
                Assert.True(forkerTask.Result.Item1 == StatusCodes.Status200OK);
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Chunk the queried pageModel pageSize.
 /// 1- If pagingIn has a too large PageSize, return a new Paging :
 ///     1.1- With the maxPageSize allowed
 ///     1.2- Reprocess page number :
 ///         1.2.1 - if original pagenumber is 0, the new is 0 too
 ///         1.2.1- else With the pageNumber reprocessed to 0. Unfriendly but OK for a first version.
 /// 2- Else return the PagingIn as is.
 /// </summary>
 /// <param name="pageModel"></param>
 /// <returns></returns>
 public static PagingParameterInModel LimitPagingIn(PagingParameterInModel pageModel, ushort maxPageSizeAllowed)
 {
     //1-
     if (pageModel != null && pageModel.PageSize > maxPageSizeAllowed)
     {
         //1.1-
         PagingParameterInModel retour = new PagingParameterInModel()
         {
             PageSize = maxPageSizeAllowed
         };
         //1.2.1-
         if (pageModel.PageNumber == 0)
         {
             retour.PageNumber = 0;
         }
         //1.2.2
         else
         {
             double ratio = pageModel.PageSize / retour.PageSize;
             retour.PageNumber = (ushort)(Math.Floor(ratio));
         }
         return(retour);
     }
     //2-
     else
     {
         return(pageModel);
     }
 }
        public void ValidatePaginationInPAgeSizeNullThrowInvalidOperationException()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageSize = 0;
            Assert.Throws <InvalidOperationException>(() => paginer.IsValid(model, CreateItems(50)));
        }
Exemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="query"></param>
 /// <param name="pageModel"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 private String GetSQLQueryMainRecordsCount(HRBirdMainInput query, PagingParameterInModel pageModel, HRSortingParamModel orderBy)
 {
     if (query == null || String.IsNullOrEmpty(query.Lang_Iso_Code))
     {
         throw new ArgumentNullException("Lang_Iso_Code not set.");
     }
     return(String.Format(SQLQUERY_COUNT, query.Lang_Iso_Code.ToLower()));
 }
        public void PaginatePaginationInInvalidThrowAInvalidArgumentException()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageNumber = 5;
            model.PageSize   = 100;
            Assert.Throws <Exception>(() => paginer.GetPaginationFromFullList(model, CreateItems(50)));
        }
        public void PaginatePaginationInWithPageSize0ThrowInvalidOperationException()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageNumber = 0;
            model.PageSize   = 0;
            Assert.Throws <InvalidOperationException>(() => paginer.GetPaginationFromFullList(model, CreateItems(50)));
        }
        private void ValidatePaginationInWith49ItemsOutOfBoundEnumerableReturnFalse()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageSize   = 50;
            model.PageNumber = 2;
            Assert.False(paginer.IsValid(model, CreateItems(49)));
        }
Exemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private PagingParameterInModel GetDefaultMainPagination()
        {
            PagingParameterInModel retour = new PagingParameterInModel()
            {
                PageNumber = 0, PageSize = 20
            };

            return(retour);
        }
        public void ValidatePaginationInFirstPageWithSinglePageEnumerableReturnTrue()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageSize   = 50;
            model.PageNumber = 0;
            Assert.True(paginer.IsValid(model, CreateItems(200)));
        }
        public void PaginateNullListsThrowArgumentNullException()
        {
            HRPaginer <String>     paginer = new HRPaginer <String>();
            PagingParameterInModel model   = new PagingParameterInModel();

            model.PageNumber = 0;
            model.PageSize   = 20;
            Assert.Throws <ArgumentNullException>(() => paginer.GetPaginationFromFullList(model, null));
        }
        public async Task <PagingParameterOutModel <int> > GetPaginatedsAsync(PagingParameterInModel pageModel)
        {
            await Task.Delay(1);

            return(new PagingParameterOutModel <int>()
            {
                CurrentPage = 44
            });
        }
Exemplo n.º 25
0
        public async Task <ActionResult <PagingParameterOutModel <HRBirdMainOutput> > > Get(
            [FromQuery] HRBirdMainInput query,
            [FromQuery] PagingParameterInModel pageModel,
            [FromQuery] HRSortingParamModel orderBy)
        {
            using var resultTask = _birdService.GetMainRecordsAsync(query, pageModel, orderBy);
            await resultTask;

            return(resultTask.Result);
        }
Exemplo n.º 26
0
        /// <summary>
        /// TODO
        /// </summary>
        /// <param name="pageModel"></param>
        /// <param name="orderBy"></param>
        /// <returns></returns>
        public async Task <PagingParameterOutModel <HRCountry> > GetCountriesAsync(PagingParameterInModel pageModel, HRSortingParamModel orderBy)
        {
            if (_workflow == null)
            {
                throw new MemberAccessException();
            }
            Task <PagingParameterOutModel <HRCountry> > retourTask = _workflow.GetQueryResultsAsync(pageModel, orderBy);
            await retourTask;

            return(retourTask.Result);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Call GetOrderedAndPaginatedsAsync with orederBy set to null.
        /// </summary>
        /// <param name="pageModel">the pageModel.</param>
        /// <returns>The HRBorders corresponding Page</returns>
        public async Task <PagingParameterOutModel <HRBorder> > GetPaginatedsAsync(PagingParameterInModel pageModel)
        {
            PagingParameterOutModel <HRBorder> retour = null;

            using (Task <PagingParameterOutModel <HRBorder> > retourTask = GetOrderedAndPaginatedsAsync(pageModel, null))
            {
                await retourTask;
                retour = retourTask.Result;
            }
            return(retour);
        }
        public async Task <PagingParameterOutModel <HRCountry> > GetPaginatedsAsync(PagingParameterInModel pageModel)
        {
            await Task.Delay(1);

            PagingParameterOutModel <HRCountry> retour = new PagingParameterOutModel <HRCountry>();

            retour.PageItems       = _countries;
            retour.PageSize        = 50;
            retour.CurrentPage     = 0;
            retour.TotalItemsCount = 50;
            return(retour);
        }
Exemplo n.º 29
0
 /// <summary>
 /// Compute the validity of the input parameter. Can throw Exceptions.
 /// </summary>
 /// <param name="model">The input Pagination Parameter</param>
 /// <param name="items">The full list of items to paginate</param>
 /// <returns>Throw ArgumentNullException if any of input parameters is null, Throw InvalidOperationException if pageSize is 0 else true if input args are valid else false.</returns>
 public bool IsValid(PagingParameterInModel model, IEnumerable <T> items)
 {
     if (items == null || model == null)
     {
         throw new ArgumentNullException();
     }
     else
     {
         IEnumerator <T> enumerator = items.GetEnumerator();
         uint            itemsCount = GetEnumerableCount(enumerator);
         return(this.IsValid(model, itemsCount));
     }
 }
Exemplo n.º 30
0
 /// <summary>
 /// 1- Process PagingInParameter if not supplied
 /// 2- Get the HRBorders from service
 /// 3- Paginate previous result
 /// !Strange we have to âss from query even for an "internal" method ... to untderstand.
 /// </summary>
 /// <param name="pageModel">The Paging Model</param>
 /// <returns>(http Status Code, PagingParameterOutModel)</returns>
 public async Task <(int, PagingParameterOutModel <HRBorder>)> GetFromPaging(
     [FromQuery] PagingParameterInModel pageModel,
     [FromQuery]  HRSortingParamModel orderBy)
 {
     if (_borderService != null)
     {
         if (orderBy != null && orderBy.IsInitialised())
         {
             if (!_borderService.IsSortable())
             {
                 return(StatusCodes.Status400BadRequest, null);
             }
             else if (!HRSortingParamModelDeserializer.IsValid(orderBy))
             {
                 return(StatusCodes.Status400BadRequest, null);
             }
         }
         //1-
         if (pageModel == null)
         {
             pageModel = GetDefaultPagingInParameter();
         }
         //!Add tu on this
         if (pageModel.PageSize > _maxPageSize)
         {
             return(StatusCodes.Status413PayloadTooLarge, null);
         }
         try
         {
             //2-
             Task <PagingParameterOutModel <HRBorder> > bordersAction = _borderService.GetBordersAsync(pageModel, orderBy);
             await bordersAction;
             //3-
             return(StatusCodes.Status200OK, bordersAction.Result);
         }
         catch (IndexOutOfRangeException)
         {
             //!Add tu on this
             return(StatusCodes.Status416RequestedRangeNotSatisfiable, null);
         }
         catch (Exception)
         {
             return(StatusCodes.Status500InternalServerError, null);
         }
     }
     else
     {
         return(StatusCodes.Status500InternalServerError, null);
     }
 }