Пример #1
0
        /// <summary>
        /// Scape show data from TVMazeApi and persist data in DB
        /// Skip shows that are already in DB
        /// </summary>
        /// <returns></returns>
        public async Task ScrapeShows()
        {
            var maxMazeShowId = await this.showRepository.GetMaxMazeId() ?? 0;

            var pageNumber = GetCurrentPageNumber(maxMazeShowId);

            var showsFromMaze = await this.tvMazeApiHttpClient.GetShowsOnPage(pageNumber);

            var showsCount = showsFromMaze.Count;

            _ = showsFromMaze.RemoveAll(s => s.Id <= maxMazeShowId);

            await this.showRepository.InsertRange(ModelMappers.ConvertShowsFromMazeToShows(showsFromMaze));

            var isEndOfShowPagesReached = showsCount == 0;

            while (!isEndOfShowPagesReached)
            {
                var tasks = Enumerable.Range(1, 10)
                            .Select(i => this.taskLimiter.LimitAsync(() => ScrapeShowAsync(++pageNumber + i)));

                var showsCountArray = await Task.WhenAll(tasks).ConfigureAwait(false);

                isEndOfShowPagesReached = showsCountArray.Any(sc => sc == 0);
            }
        }
Пример #2
0
        private async Task <int> ScrapeShowAsync(int pageNumber)
        {
            var showsFromMaze = await this.tvMazeApiHttpClient.GetShowsOnPage(++pageNumber);

            await this.showRepository.InsertRange(ModelMappers.ConvertShowsFromMazeToShows(showsFromMaze));

            return(showsFromMaze.Count);
        }
        public void ConvertShowsFromMazeToShows()
        {
            // Arrange
            var expected      = GetShows() as List <Show>;
            var showsFromMaze = GetShowsFromMaze();

            // Act
            var result = ModelMappers.ConvertShowsFromMazeToShows(showsFromMaze as List <ShowDataMaze>);

            // Assert
            _ = result.Should().BeEquivalentTo(expected);
        }