Пример #1
0
        public async Task <TorrentsViewModel> GetTorrentsAsync(SearchAndFilterCriteria criteria, int?pageIndex)
        {
            if (criteria == null)
            {
                throw new AppException(ExceptionEvent.InvalidParameters, "Criteria can't be null.");
            }
            if (pageIndex.HasValue && pageIndex.Value < 0)
            {
                throw new AppException(ExceptionEvent.InvalidParameters, "Page can't be negative.");
            }

            return(await _customHttpClient.PostJsonAsync <TorrentsViewModel>($"api/Torrents/GetTorrents/?pageIndex={pageIndex}", criteria));
        }
Пример #2
0
        public async Task <TorrentsViewModel> GetTorrents(int pageIndex, SearchAndFilterCriteria criteria)
        {
            var(torrents, count) = await _torrentsService.GetTorrentsAndCount(pageIndex, Constants.ITEMS_PER_PAGE, criteria.SearchText, criteria.SubcategoryId,
                                                                              criteria.Size.From, criteria.Size.To, criteria.Date.From, criteria.Date.To);

            return(new TorrentsViewModel
            {
                Torrents = _mapper.Map <TorrentView[]>(torrents),
                PaginationInfo = new PaginationInfoViewModel
                {
                    TotalItems = count,
                    CurrentPage = pageIndex,
                    PageSize = Constants.ITEMS_PER_PAGE
                }
            });
        }
Пример #3
0
        public async Task GetTorrents_ValidParameters_ReturnTheRequestedTorrentPage(int pageIndex, int expectedCount)
        {
            //Arrange
            var criteria = new SearchAndFilterCriteria();

            //Act
            var torrents = await _client.PostJsonAsync <TorrentsViewModel>($"/api/Torrents/GetTorrents/?pageIndex={pageIndex}", criteria);

            //Assert
            Assert.NotNull(torrents);
            Assert.NotNull(torrents.Torrents);
            Assert.NotNull(torrents.PaginationInfo);
            Assert.True(expectedCount == torrents.Torrents.Count(),
                        $"Expected count={expectedCount} doesn't match the actual count={torrents.Torrents.Count()}");
            Assert.True(pageIndex == torrents.PaginationInfo.CurrentPage,
                        $"Expected page={pageIndex} doesn't match the actual page={torrents.PaginationInfo.CurrentPage}");
        }
Пример #4
0
        public async Task GetTorrents_InvalidParameters_ReturnBadRequest(int pageIndex, SearchAndFilterCriteria criteria)
        {
            //Act
            var exception = await Assert.ThrowsAsync <HttpRequestException>(async() =>
                                                                            await _client.PostJsonAsync($"/api/Torrents/GetTorrents/?pageIndex={pageIndex}", criteria));

            //Assert
            Assert.True("Response status code does not indicate success: 400 (Bad Request)." == exception.Message,
                        $"Expected 400(Bad Request) error code, actual - {exception.Message}");
        }