public async Task Given_An_Article_If_Not_Published_To_Queue_IsSuccessful_Should_Be_False()
        {
            // Arrange
            var article = new Article();

            _wikiArticle.Details(Arg.Any <int>()).Returns(new ExpandedArticleResultSet {
                Items = new Dictionary <string, ExpandedArticle>
                {
                    ["key"] = new ExpandedArticle
                    {
                        Id       = 24324,
                        Abstract = "OCG in effect since September 1, 2007."
                    }
                }
            });

            _wikiArticle.Simple(Arg.Any <long>()).Returns(new ContentResult {
                Sections = new Section[0]
            });
            _banlistDataQueue.Publish(Arg.Any <ArticleProcessed>()).Returns(new YugiohBanlistCompletion());

            // Act
            var result = await _sut.Process(article);

            // Assert
            result.IsSuccessful.Should().BeFalse();
        }
        public async Task <ArticleTaskResult> Process(Article article)
        {
            var articleTaskResult = new ArticleTaskResult {
                Article = article
            };

            if (!article.Title.Equals("Archetype", StringComparison.OrdinalIgnoreCase))
            {
                var articleDetailsList = await _wikiArticle.Details((int)article.Id);

                var articleDetails = articleDetailsList.Items.First();

                var epoch = articleDetails.Value.Revision.Timestamp;

                var thumbNailUrl = _archetypeWebPage.ArchetypeThumbnail(articleDetails, article.Url);

                var archetype = new Archetype
                {
                    Id         = article.Id,
                    Name       = article.Title,
                    Revision   = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(epoch),
                    ImageUrl   = thumbNailUrl,
                    ProfileUrl = article.Url
                };

                await _queue.Publish(archetype);
            }

            return(articleTaskResult);
        }
        public async Task <string> FromArticleId(int articleId)
        {
            var profileDetailsList = await _wikiArticle.Details(articleId);

            var profileDetails = profileDetailsList.Items.First();

            return(ImageHelper.ExtractImageUrl(profileDetails.Value.Thumbnail));
        }
Пример #4
0
        public async Task <string> FromArticleId(int articleId)
        {
            var profileDetailsList = await _wikiArticle.Details(articleId);

            var profileDetails = profileDetailsList.Items.First();

            return(FromArticleDetails(profileDetails));
        }
        public async Task Given_An_Article_Id_Should_Invoke_Wikia_Details_Method_Once()
        {
            // Arrange
            const int expected  = 1;
            const int articleId = 666747;

            _wikiArticle.Details(Arg.Any <int>()).Returns(new ExpandedArticleResultSet
            {
                Items = new Dictionary <string, ExpandedArticle>
                {
Пример #6
0
        public void Given_Null_RequestParameters_Should_Throw_ArgumentNullException()
        {
            // Arrange

            // Act
            Func <Task <ExpandedArticleResultSet> > act = () => _sut.Details((ArticleDetailsRequestParameters)null);

            // Assert
            act.ShouldThrow <ArgumentNullException>();
        }
Пример #7
0
        public async Task Given_A_Valid_Article_If_Processed_Successfully_IsSuccessful_Should_Be_True()
        {
            // Arrange
            var article = new Article
            {
                CorrelationId = Guid.NewGuid(),
                Id            = 909890,
                Title         = "Blue-Eyes",
                Url           = "http://yugioh.wikia.com/wiki/Blue-Eyes"
            };

            _wikiArticle.Details(Arg.Any <int>()).Returns(new ExpandedArticleResultSet
            {
                Items = new Dictionary <string, ExpandedArticle>
                {
        public async Task Given_An_Invalid_Banlist_Article_Should_Not_Execute_Update_AddOrUpdate_Method()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "January 2018 Lists", Url = "/wiki/January_2018_Lists"
            };

            var expandedArticleResultSet = new ExpandedArticleResultSet {
                Items = new Dictionary <string, ExpandedArticle>()
            };

            expandedArticleResultSet.Items.Add("test", new ExpandedArticle {
                Id = 23422, Abstract = string.Empty
            });
            _wikiArticle.Details(Arg.Any <int>()).Returns(expandedArticleResultSet);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _yugiohBanlistService.DidNotReceive().AddOrUpdate(Arg.Any <YugiohBanlist>());
        }
Пример #9
0
        public async Task <ArticleProcessed> Process(Article article)
        {
            var response = new ArticleProcessed {
                Article = article
            };

            var articleDetailsList = await _wikiArticle.Details((int)article.Id);

            var(_, expandedArticle) = articleDetailsList.Items.First();

            var banlistArticleSummary = BanlistHelpers.ExtractBanlistArticleDetails(expandedArticle.Id, expandedArticle.Abstract);

            if (banlistArticleSummary != null)
            {
                const char beginChar = '「';
                const char endChar   = '」';

                var banlist = new YugiohBanlist
                {
                    ArticleId   = banlistArticleSummary.ArticleId,
                    Title       = expandedArticle.Title,
                    BanlistType = banlistArticleSummary.BanlistType,
                    StartDate   = banlistArticleSummary.StartDate
                };

                var banlistContentResult = await _wikiArticle.Simple(banlistArticleSummary.ArticleId);

                _logger.LogInformation($"{banlist.BanlistType.ToString()}, {banlist.Title}, {banlist.StartDate}");
                foreach (var section in banlistContentResult.Sections)
                {
                    // skip references section
                    if (section.Title.ToLower() == "references")
                    {
                        continue;
                    }

                    // new section
                    var ybls = new YugiohBanlistSection
                    {
                        Title   = StringHelpers.RemoveBetween(section.Title, beginChar, endChar).Trim(),
                        Content = ContentResultHelpers.GetSectionContentList(section).OrderBy(c => c).ToList()
                    };

                    // remove invalid characters
                    if (ybls.Content.Any())
                    {
                        ybls.Content = ybls.Content.Select(c => StringHelpers.RemoveBetween(c, beginChar, endChar)).ToList();
                    }

                    banlist.Sections.Add(ybls);
                }

                response.Banlist = banlist;

                var publishBanlistResult = await _banlistDataQueue.Publish(new ArticleProcessed { Article = article, Banlist = banlist });

                response.IsSuccessful = publishBanlistResult.IsSuccessful;
            }

            return(response);
        }
Пример #10
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            var articleDetailsList = await _wikiArticle.Details(item.Id);

            var articleDetails = articleDetailsList.Items.First();

            var banlistArticleSummary = BanlistHelpers.ExtractBanlistArticleDetails(articleDetails.Value.Id, articleDetails.Value.Abstract);

            if (banlistArticleSummary != null)
            {
                const char beginChar = '「';
                const char endChar   = '」';

                var banlist = new YugiohBanlist
                {
                    ArticleId   = banlistArticleSummary.ArticleId,
                    Title       = articleDetails.Value.Title,
                    BanlistType = banlistArticleSummary.BanlistType,
                    StartDate   = banlistArticleSummary.StartDate
                };


                var banlistContentResult = await _wikiArticle.Simple(banlistArticleSummary.ArticleId);

                foreach (var section in banlistContentResult.Sections)
                {
                    // skip references section
                    if (section.Title.ToLower() == "references")
                    {
                        continue;
                    }

                    // new section
                    var ybls = new YugiohBanlistSection
                    {
                        Title   = StringHelpers.RemoveBetween(section.Title, beginChar, endChar).Trim(),
                        Content = ContentResultHelpers.GetSectionContentList(section).OrderBy(c => c).ToList()
                    };

                    // remove invalid characters
                    if (ybls.Content.Any())
                    {
                        ybls.Content = ybls.Content.Select(c => StringHelpers.RemoveBetween(c, beginChar, endChar)).ToList();
                    }

                    banlist.Sections.Add(ybls);
                }

                await _banlistService.AddOrUpdate(banlist);

                response.Data = banlist;

                response.IsSuccessfullyProcessed = true;
            }

            return(response);
        }