Ejemplo n.º 1
0
        public void RetrievingListCorrectlyRetrievesUserInformation()
        {
            // arrange
            const string user        = "******";
            var          fixture     = new ListRetrievalWorkerFixture();
            var          path        = AppDomain.CurrentDomain.BaseDirectory;
            var          examplePath = Path.Combine(path, "PageExamples", "UserList.xml");
            var          data        = File.ReadAllText(examplePath);

            fixture.PageRetrieverMock
            .Setup(t => t.RetrieveDocumentAsStringAsync(MalRouteBuilder.UserListUrl(user)))
            .ReturnsAsync(new StringRetrievalWrapper(HttpStatusCode.OK, true, data));

            var sut = fixture.Instance;

            // act
            var result = sut.RetrieveUserListAsync(user).Result;

            // assert
            result.Info.Should().NotBeNull();
            result.Info.UserId.Should().Be("112255");
            result.Info.Username.Should().Be("Test");
            result.Info.Watching.Should().Be(47);
            result.Info.Completed.Should().Be(490);
            result.Info.OnHold.Should().Be(2);
            result.Info.Dropped.Should().Be(23);
            result.Info.PlanToWatch.Should().Be(886);
            result.Info.DaysWatching.Should().Be(93.98);
        }
Ejemplo n.º 2
0
        public void RetrievingListCorrectlyRetrievesAnimeInformation()
        {
            // arrange
            const string user        = "******";
            var          fixture     = new ListRetrievalWorkerFixture();
            var          path        = AppDomain.CurrentDomain.BaseDirectory;
            var          examplePath = Path.Combine(path, "PageExamples", "UserList.xml");
            var          data        = File.ReadAllText(examplePath);

            fixture.PageRetrieverMock
            .Setup(t => t.RetrieveDocumentAsStringAsync(MalRouteBuilder.UserListUrl(user)))
            .ReturnsAsync(new StringRetrievalWrapper(HttpStatusCode.OK, true, data));

            var sut = fixture.Instance;

            // act
            var result = sut.RetrieveUserListAsync(user).Result;

            // assert
            result.Anime.Count.Should().Be(2);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieve a user's MAL list
        /// </summary>
        /// <param name="username">User's username</param>
        /// <returns>Mal list</returns>
        public async Task <UserList> RetrieveUserListAsync(string username)
        {
            var userList         = new UserList();
            var retrievalWrapper =
                await _pageRetriever.RetrieveDocumentAsStringAsync(MalRouteBuilder.UserListUrl(username));

            try
            {
                var xml       = XDocument.Parse(retrievalWrapper.RetrievedBody);
                var userInfo  = xml.Root?.Element("myinfo");
                var userAnime = xml.Root?.Elements("anime").ToList();

                if (userInfo == null || userAnime.Count == 0)
                {
                    throw new Exception("Failed to retrieve or parse User's My Anime List");
                }

                var xmlInfoSerializer = new XmlSerializer(typeof(UserListInformation));
                var info = (UserListInformation)xmlInfoSerializer.Deserialize(userInfo.CreateReader());
                userList.Info = info;

                var xmlAnimeSerializer = new XmlSerializer(typeof(UserListAnime));
                foreach (var item in userAnime)
                {
                    var anime = (UserListAnime)xmlAnimeSerializer.Deserialize(item.CreateReader());
                    userList.Anime.Add(anime);
                }
            }
            catch (Exception exception)
            {
                userList.ErrorOccured = true;
                userList.ErrorMessage = exception.Message;
            }

            return(userList);
        }