コード例 #1
0
        public void Given_An_Invalid_TitleText_Should_Return_Null(string titleText)
        {
            // Arrange
            // Act
            var result = BanlistHelpers.ExtractBanlistArticleDetails(Arg.Any <int>(), titleText);

            // Assert
            result.Should().BeNull();
        }
コード例 #2
0
        public void Given_A_Banlist_TitleText_And_An_ArticleId_Should_Assign_ArticleId_To_Returned_BanlistArticleSummary(int article, string titleText, int expected)
        {
            // Arrange

            // Act
            var result = BanlistHelpers.ExtractBanlistArticleDetails(article, titleText);

            // Assert
            result.ArticleId.Should().Be(expected);
        }
コード例 #3
0
        public void Given_A_Banlist_TitleText_Should_Extract_Banlist_StartDate(string titleText, DateTime expected)
        {
            // Arrange

            // Act
            var result = BanlistHelpers.ExtractBanlistArticleDetails(Arg.Any <int>(), titleText);

            // Assert
            result.StartDate.Should().Be(expected);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }