コード例 #1
0
ファイル: PersonTests.cs プロジェクト: N0D4N/jikan.net
        public async Task GetPerson_CorrectId_ShouldReturnNotNullPerson(long malId)
        {
            // Given
            var returnedPerson = await _jikan.GetPerson(malId);

            // Then
            returnedPerson.Should().NotBeNull();
        }
コード例 #2
0
ファイル: JikanService.cs プロジェクト: Kadantte/Seiyuu.moe
        public async Task <MalSeiyuuUpdateData> GetSeiyuuDataAsync(long malId)
        {
            var parsedData = await _jikanClient.GetPerson(malId);

            if (parsedData is null)
            {
                return(null);
            }


            return(new MalSeiyuuUpdateData(
                       parsedData.Name,
                       parsedData.More,
                       $"{parsedData.FamilyName ?? string.Empty} {parsedData.GivenName ?? string.Empty}".Trim(),
                       EmptyStringIfPlaceholder(parsedData.ImageURL),
                       parsedData.MemberFavorites,
                       parsedData.Birthday,
                       parsedData.VoiceActingRoles?.Select(
                           x => new MalVoiceActingRoleUpdateData(
                               x.Anime.MalId,
                               x.Character.MalId,
                               x.Role
                               )
                           )
                       .ToList() ?? new List <MalVoiceActingRoleUpdateData>()
                       ));
        }
コード例 #3
0
ファイル: JikanParser.cs プロジェクト: Akenaide/Seiyuu.moe
        private async Task <Person> SendSinglePersonRequest(long malId, short retryCount)
        {
            Person seiyuu = null;
            await Task.Delay(3000 + retryCount * 10000);

            try
            {
                seiyuu = await jikan.GetPerson(malId);
            }
            catch (Exception ex)
            {
                if (retryCount < 10)
                {
                    if (ex.InnerException is JikanRequestException && (ex.InnerException as JikanRequestException).ResponseCode == System.Net.HttpStatusCode.TooManyRequests)
                    {
                        retryCount++;
                        return(await SendSinglePersonRequest(malId, retryCount));
                    }
                    else
                    {
                        if (ex.InnerException is JikanRequestException)
                        {
                            System.Net.HttpStatusCode responseCode = (ex.InnerException as JikanRequestException).ResponseCode;

                            switch (responseCode)
                            {
                            case (System.Net.HttpStatusCode.NotFound):
                                BlacklistId(malId, "Seiyuu", "404 Not Found");
                                break;

                            case (System.Net.HttpStatusCode.InternalServerError):
                                //	BlacklistId(malId, "Seiyuu", "Not exist");
                                break;

                            case (System.Net.HttpStatusCode.TooManyRequests):
                                BlacklistId(malId, "Seiyuu", "429 Too much request");
                                break;

                            default:
                                BlacklistId(malId, "Seiyuu", "Other");
                                break;
                            }
                        }
                    }
                }
            }

            return(seiyuu);
        }
コード例 #4
0
 public void GetPerson_WrongIdDoNotSurpressExceptions_ShouldThrowJikanRequestExceptionGetPerson()
 {
     Assert.ThrowsAnyAsync <JikanRequestException>(() => jikan.GetPerson(13308));
 }
コード例 #5
0
 public void ShouldThrowJikanRequestExceptionGetPerson()
 {
     Assert.ThrowsAnyAsync <JikanRequestException>(() => jikan.GetPerson(13308));
 }
コード例 #6
0
        public async Task GetPerson_CorrectId_ShouldReturnNotNullPerson(long malId)
        {
            Person returnedPerson = await _jikan.GetPerson(malId);

            Assert.NotNull(returnedPerson);
        }
コード例 #7
0
        public void ShouldReturnNotNullPerson(long malId)
        {
            Person returnedPerson = Task.Run(() => jikan.GetPerson(malId)).Result;

            Assert.NotNull(returnedPerson);
        }