Esempio n. 1
0
        public void RetrievingSeiyuuInformationWorksCorrectly()
        {
            // arrange
            const int seiyuuId = 40;
            var       fixture  = new RequestProcessorFixture();

            var document    = new HtmlDocument();
            var path        = AppDomain.CurrentDomain.BaseDirectory;
            var examplePath = Path.Combine(path, "PageExamples", $"{seiyuuId}.html");

            using (var htmlFile = File.Open(examplePath, FileMode.Open))
            {
                document.Load(htmlFile);
            }

            fixture.PageRetrieverMock
            .Setup(t => t.RetrieveHtmlPageAsync(MalRouteBuilder.SeiyuuUrl(seiyuuId)))
            .ReturnsAsync(new HtmlDocumentRetrievalWrapper(HttpStatusCode.OK, true, document));

            var sut = fixture.Instance;

            // act
            var retrievalWrapper = sut.DoSeiyuuRetrieval(seiyuuId).Result;

            // assert
            retrievalWrapper.ResponseStatusCode.Should().Be(HttpStatusCode.OK);
            retrievalWrapper.Success.Should().BeTrue();
            retrievalWrapper.ResponseData.Id.Should().Be(seiyuuId);
            retrievalWrapper.ResponseData.Name.Should().Be("Mamiko Noto");
            retrievalWrapper.ResponseData.ErrorOccured.Should().BeFalse();
        }
Esempio n. 2
0
        /// <summary>
        /// Retrieve a Seiyuu from MAL
        /// </summary>
        /// <param name="seiyuuId"></param>
        /// <returns></returns>
        public async Task <RetrievalWrapper <Seiyuu> > DoSeiyuuRetrieval(int seiyuuId)
        {
            var seiyuu = new Seiyuu
            {
                Id = seiyuuId
            };

            try
            {
                var seiyuuResponse = await _pageRetriever.RetrieveHtmlPageAsync(MalRouteBuilder.SeiyuuUrl(seiyuuId));

                if (seiyuuResponse.ResponseStatusCode == null)
                {
                    throw seiyuuResponse.Exception;
                }
                var seiyuuDoc = seiyuuResponse.Document;

                seiyuu
                .RetrieveName(seiyuuDoc)
                .RetrieveGivenName(seiyuuDoc)
                .RetrieveFamilyName(seiyuuDoc)
                .RetrieveBirthday(seiyuuDoc)
                .RetrieveAdditionalInformation(seiyuuDoc)
                .RetrieveWebsite(seiyuuDoc)
                .RetrieveRoles(seiyuuDoc);
                return(new RetrievalWrapper <Seiyuu>(seiyuuResponse.ResponseStatusCode.Value, seiyuuResponse.Success,
                                                     seiyuu));
            }
            catch (Exception exception)
            {
                seiyuu.ErrorOccured = true;
                seiyuu.ErrorMessage = exception.Message;
                return(new RetrievalWrapper <Seiyuu>(exception, seiyuu));
            }
        }
Esempio n. 3
0
        public void LoadingSeiyuuWithErrorCorrectlyMarksAsBroken()
        {
            // arrange
            const int seiyuuId = 40;
            var       fixture  = new RequestProcessorFixture();

            fixture.PageRetrieverMock
            .Setup(t => t.RetrieveHtmlPageAsync(MalRouteBuilder.SeiyuuUrl(seiyuuId)))
            .Throws(new Exception("Cannot load"));

            var sut = fixture.Instance;

            // act
            var retrievalWrapper = sut.DoSeiyuuRetrieval(seiyuuId).Result;

            // assert
            retrievalWrapper.Exception.Should().NotBeNull();
            retrievalWrapper.ResponseData.ErrorOccured.Should().BeTrue();
            retrievalWrapper.ResponseData.ErrorMessage.Should().Be("Cannot load");
        }