コード例 #1
0
        public async Task <List <Show> > GetShows(IShowRepository showRepository, int pageNumber)
        {
            var shows = new List <Show>();

            _logger.LogInformation($"Stating copying data from {nameof(pageNumber)} {pageNumber}");

            var showDtos = await _tvMazeService.GetShowsByPage(pageNumber).ConfigureAwait(false);

            _logger.LogInformation($"Found {showDtos.Count} Shows from TvMaze API service");

            foreach (var showDto in showDtos)
            {
                var tvMazeShowWithCast = await _tvMazeService.GetShowDataById(showDto.Id).ConfigureAwait(false);

                _logger.LogInformation($"Found TvMaze show {tvMazeShowWithCast} with cast");

                var show = new Show {
                    Id = tvMazeShowWithCast.Id, Name = tvMazeShowWithCast.Name
                };

                show.Cast.AddRange(tvMazeShowWithCast.Cast
                                   .TakeWhile(personDto => personDto != null)
                                   .Distinct(new PersonDtoEqualityComparer())
                                   .Select(personDto => new Cast
                {
                    CastPersonId = personDto.Id,
                    ShowId       = show.Id,
                    Person       = GetPerson(showRepository, personDto)
                }));

                shows.Add(show);
            }
            return(shows);
        }
コード例 #2
0
ファイル: UnitTests.cs プロジェクト: debabrata-das/tvmaze
        public void GetShowDataById_WhenApiServiceReturns401_ShouldRecieveUnauthorizedFlurlHttpException()
        {
            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(null, 401);

                var tvMazeService = new TvMazeService(_jsonJsonApiDataReader, GetLogger());

                var showData = tvMazeService.GetShowDataById(1);

                try
                {
                    showData.Wait();
                }
                catch (AggregateException aggregateException)
                {
                    aggregateException.Handle(exception =>
                    {
                        Assert.IsTrue(exception is FlurlHttpException flurlHttpException &&
                                      flurlHttpException.Call.HttpStatus == HttpStatusCode.Unauthorized);
                        return(true);
                    });
                }
            }
        }
コード例 #3
0
ファイル: UnitTests.cs プロジェクト: debabrata-das/tvmaze
        public void GetShowDataById_WhereShowIdEqualsARandomId_ExpectsReturnDataToMatchId()
        {
            var randomId = new Random().Next(1, 10000);

            using (var httpTest = new HttpTest())
            {
                httpTest.RespondWithJson(new JObject {
                    { "id", randomId }
                });

                var sut = new TvMazeService(_jsonJsonApiDataReader, GetLogger());

                var showData = sut.GetShowDataById(randomId);

                showData.Wait();

                Assert.IsTrue(showData.Result.Id == randomId);
            }
        }