Esempio n. 1
0
        private IPageable ResolvePageableArgumentFromQueryString(QueryString queryString)
        {
            var pageNumberString = queryString.GetParameter(_binderConfig.PageParameterName);
            var pageSizeString   = queryString.GetParameter(_binderConfig.SizeParameterName);

            var pageNumber = ParseIntOrDefault(pageNumberString, _binderConfig.FallbackPageable.PageNumber);
            var pageSize   = ParseIntOrDefault(pageSizeString, _binderConfig.FallbackPageable.PageSize,
                                               _binderConfig.MaxPageSize);

            return(Pageable.Of(pageNumber, pageSize));
        }
        public async Task DataFlow_FindPageAndMap_Test()
        {
            IPostsRepository postsRepository = new PostsRepository();

            IoCManager.Resolver.InjectProperties(postsRepository);

            var findAllResult = await postsRepository.FindAll();

            Assert.IsEmpty(findAllResult);

            var postCount  = 0;
            var savedPosts = await postsRepository.SaveAll(
                new[]
            {
                new PostEntity {
                    Title = $"{postCount}", Content = $"{postCount++}"
                },
                new PostEntity {
                    Title = $"{postCount}", Content = $"{postCount++}"
                },
                new PostEntity {
                    Title = $"{postCount}", Content = $"{postCount++}"
                },
                new PostEntity {
                    Title = $"{postCount}", Content = $"{postCount++}"
                },
                new PostEntity {
                    Title = $"{postCount}", Content = $"{postCount++}"
                },
            });

            Assert.IsNotNull(savedPosts);
            Assert.IsNotEmpty(savedPosts);
            Assert.AreEqual(postCount, savedPosts.Count);

            var foundPage = await postsRepository.FindAll(Pageable.Of(1, 2));

            Assert.IsNotNull(foundPage);
            Assert.IsNotNull(foundPage.PageInfo);
            Assert.AreEqual(postCount, foundPage.Total);

            Assert.IsNotNull(foundPage.Content);
            Assert.AreEqual(2, foundPage.Content.Count);

            Assert.IsNotNull(foundPage.Content[0]);
            Assert.AreEqual("2", foundPage.Content[0].Title);

            Assert.IsNotNull(foundPage.Content[1]);
            Assert.AreEqual("3", foundPage.Content[1].Title);


            var mappedPage = foundPage.Map(entity => entity.Title);

            Assert.IsNotNull(mappedPage);
            Assert.IsNotNull(mappedPage.PageInfo);
            Assert.AreEqual(postCount, mappedPage.Total);

            Assert.IsNotNull(mappedPage.Content);
            Assert.AreEqual(2, mappedPage.Content.Count);
            Assert.AreEqual("2", mappedPage.Content[0]);
            Assert.AreEqual("3", mappedPage.Content[1]);
        }