コード例 #1
0
        public async Task Given_A_Valid_ArticleList_Collection_Should_Execute_Process()
        {
            // Arrange
            var fixture = new Fixture {
                RepeatCount = 4
            };
            var          articles          = fixture.Create <UnexpandedArticle[]>();
            const string aCategory         = "a category";
            var          unexpandedArticle = new UnexpandedArticle();

            _articleProcessor
            .Process(aCategory, unexpandedArticle)
            .ReturnsForAnyArgs
            (
                x => new ArticleTaskResult {
                IsSuccessfullyProcessed = true
            },
                x => new ArticleTaskResult {
                IsSuccessfullyProcessed = true
            },
                x => null,
                x => null
            );

            // Act
            await _sut.Process(aCategory, articles);

            // Assert
            await _articleProcessor.Received(4).Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>());
        }
コード例 #2
0
        public async Task Given_A_Banlist_Article_Should_Execute_WikiArticle_Simple_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 = "These are the January 2018 Forbidden and Limited Lists for the OCG in effect since January 1, 2018"
            });
            _wikiArticle.Details(Arg.Any <int>()).Returns(expandedArticleResultSet);
            _wikiArticle.Simple(Arg.Any <int>()).Returns(new ContentResult {
                Sections = new Section[0]
            });

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _wikiArticle.Received(1).Simple(Arg.Any <int>());
        }
コード例 #3
0
        public async Task Given_A_Banlist_Article_Should_Skip_Reference_Sections()
        {
            // 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 = "These are the January 2018 Forbidden and Limited Lists for the OCG in effect since January 1, 2018"
            });
            _wikiArticle.Details(Arg.Any <int>()).Returns(expandedArticleResultSet);
            _wikiArticle.Simple(Arg.Any <int>()).Returns(new ContentResult {
                Sections = new[] { new Section {
                                       Title = "References"
                                   } }
            });

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

            var yugiohBanlist = (YugiohBanlist)result.Data;

            // Assert
            yugiohBanlist.Sections.Should().BeEmpty();
        }
コード例 #4
0
        public async Task <ArticleTaskResult> Process(string category, UnexpandedArticle article)
        {
            try
            {
                _logger.LogInformation("Processing article '{@Title}', category '{@Category}'",
                                       article.Title ?? article.Id.ToString(), category);

                var articleResult = await _articleProcessor.Process(category, article);

                _logger.LogInformation("Finished processing article '{@Title}', category '{@Category}'",
                                       article.Title ?? article.Id.ToString(), category);

                articleResult.IsSuccessfullyProcessed = true;

                return(articleResult);
            }
            catch (ArgumentNullException ex)
            {
                _logger.LogError("Error processing article '{@Title}', category '{@Category}'. ArgumentNullException: {@Exception}", article.Title, category, ex);
                throw;
            }
            catch (InvalidOperationException ex)
            {
                _logger.LogError("Error processing article '{@Title}', category '{@Category}'. InvalidOperationException, IArticleItemProcessor not found: {@Exception}", article.Title, category, ex);
                throw;
            }
        }
コード例 #5
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var articleTaskResult = new ArticleTaskResult {
                Article = item
            };

            try
            {
                await _queue.Publish(item);

                articleTaskResult.IsSuccessfullyProcessed = true;
            }
            catch (Exception ex)
            {
                articleTaskResult.Failed = new ArticleException {
                    Article = item, Exception = ex
                };
            }

            return(articleTaskResult);
        }
コード例 #6
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            var card = await _cardService.CardByName(item.Title);

            if (card != null)
            {
                var triviaSections = new List <CardTriviaSection>();

                var articleCardTrivia = await _wikiArticle.Simple(item.Id);

                foreach (var cardTriviaSection in articleCardTrivia.Sections)
                {
                    if (cardTriviaSection.Title.Equals("References", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var rulingSection = new CardTriviaSection
                    {
                        Name   = cardTriviaSection.Title,
                        Trivia = SectionHelper.GetSectionContentList(cardTriviaSection)
                    };

                    triviaSections.Add(rulingSection);
                }

                await _cardTriviaService.Update(card.Id, triviaSections);
            }

            return(response);
        }
コード例 #7
0
        public Task Publish(UnexpandedArticle article)
        {
            var messageToBeSent = new Article
            {
                Id            = article.Id,
                CorrelationId = Guid.NewGuid()
            };

            return(_queue.Publish(messageToBeSent));
        }
コード例 #8
0
        public async Task Given_A_Valid_Article_Should_Process_Article_Successfully()
        {
            // Arrange
            var article = new UnexpandedArticle();

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

            // Assert
            result.IsSuccessfullyProcessed.Should().BeTrue();
        }
コード例 #9
0
        public async Task Given_An_UnexpandedArticle_Should_Invoke_Publish_Method_Once()
        {
            // Arrange
            const int expected          = 1;
            var       unexpandedArticle = new UnexpandedArticle();

            // Act
            await _sut.Publish(unexpandedArticle);

            // Assert
            await _queue.Received(expected).Publish(Arg.Is(unexpandedArticle));
        }
コード例 #10
0
        public Task Publish(UnexpandedArticle message)
        {
            var messageToBeSent = new Article
            {
                Id            = message.Id,
                CorrelationId = Guid.NewGuid(),
                Title         = message.Title,
                Url           = new Uri(new Uri(_appSettings.Value.WikiaDomainUrl), message.Url).AbsoluteUri
            };

            return(Publish(messageToBeSent));
        }
コード例 #11
0
        public async Task Given_A_Valid_Article_If_An_Exception_Is_Thrown_IsSuccessfullyProcessed_Variable_Should_False()
        {
            // Arrange
            var article = new UnexpandedArticle();

            _archetypeArticleQueue.Publish(Arg.Any <UnexpandedArticle>()).Throws(new Exception());

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

            // Assert
            result.IsSuccessfullyProcessed.Should().BeFalse();
        }
コード例 #12
0
        public async Task Given_A_Valid_Article_If_An_Exception_Is_Thrown_Exception_Variable_Should_Be_Initialised()
        {
            // Arrange
            var article = new UnexpandedArticle();

            _banlistArticleQueue.Publish(Arg.Any <UnexpandedArticle>()).Throws(new Exception());

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

            // Assert
            result.Failed.Should().NotBeNull();
        }
コード例 #13
0
        public async Task Given_A_Valid_Article_Should_Execute_GetYugiohCard()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Blue-Eyes", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _cardWebPage.GetYugiohCard(Arg.Any <string>()).Returns((YugiohCard)null);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            _cardWebPage.Received(1).GetYugiohCard(Arg.Any <Uri>());
        }
        public async Task Given_A_Category_And_A_SemanticCard_Should_Execute_Process()
        {
            // Arrange
            var category          = "Flip";
            var unexpandedArticle = new UnexpandedArticle {
                Title = "Red-Eyes Black Dragon"
            };

            _articleProcessor.Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>()).Returns(new ArticleTaskResult());

            // Act
            await _sut.Process(category, unexpandedArticle);

            // Assert
            await _articleProcessor.Received(1).Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>());
        }
        public async Task Given_A_CardsByArchetype_Article_Should_Execute_ArchetypeByName()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Clear Wing", Url = "/wiki/List_of_\"Clear_Wing\"_cards"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeService.ArchetypeByName(Arg.Any <string>()).Returns((Archetype)null);
            _archetypeService.Add(Arg.Any <AddArchetypeCommand>()).Returns((Archetype)null);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _archetypeService.Received(1).ArchetypeByName(Arg.Any <string>());
        }
コード例 #16
0
        public async Task Given_A_Valid_Article_And_YugiohCard_Info_Is_Extracted_Should_Execute_AddOrUpdate()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Blue-Eyes", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _cardWebPage.GetYugiohCard(Arg.Any <Uri>()).Returns(new YugiohCard());
            _yugiohCardService.AddOrUpdate(Arg.Any <YugiohCard>()).Returns((Card)null);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _yugiohCardService.Received(1).AddOrUpdate(Arg.Any <YugiohCard>());
        }
コード例 #17
0
        public async Task Given_A_Valid_Article_And_YugiohCard_Info_Is_Extracted_IsSuccessful_Should_BeTrue()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Blue-Eyes", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _cardWebPage.GetYugiohCard(Arg.Any <Uri>()).Returns(new YugiohCard());
            _yugiohCardService.AddOrUpdate(Arg.Any <YugiohCard>()).Returns(new Card());

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

            // Assert
            result.IsSuccessfullyProcessed.Should().BeTrue();
        }
コード例 #18
0
        public async Task Given_A_New_Archetype_Article_Should_Not_Execute_Update_ServiceMethod()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Blue-Eyes", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeWebPage.Cards(Arg.Any <Uri>()).Returns(new List <string> {
                "Blue-Eyes White Dragon"
            });
            _archetypeService.Add(Arg.Any <AddArchetypeCommand>()).Returns(new Archetype());

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _archetypeService.DidNotReceive().Update(Arg.Any <UpdateArchetypeCommand>());
        }
コード例 #19
0
        public async Task Given_An_Archetype_If_Title_Equals_Archetype_IsSuccessfullyProcessed_Should_Be_False()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Archetype", Url = "/wiki/Blue-Eyes"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeWebPage.Cards(Arg.Any <Uri>()).Returns(new List <string> {
                "Blue-Eyes White Dragon"
            });
            _archetypeService.Update(Arg.Any <UpdateArchetypeCommand>()).Returns(new Archetype());

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

            // Assert
            result.IsSuccessfullyProcessed.Should().BeFalse();
        }
        public async Task Given_A_CardsByArchetype_Article_IsSuccessful_Should_Be_True()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Clear Wing", Url = "/wiki/List_of_\"Clear_Wing\"_cards"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeService.ArchetypeByName(Arg.Any <string>()).Returns(new Archetype());
            _archetypeWebPage.Cards(Arg.Any <Uri>()).Returns(new List <string> {
                "Blue-Eyes White Dragon"
            });
            _archetypeCardsService.Update(Arg.Any <UpdateArchetypeCardsCommand>()).Returns(new List <ArchetypeCard>());

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

            // Assert
            result.IsSuccessfullyProcessed.Should().BeTrue();
        }
        public async Task Given_A_CardsByArchetype_Article_Should_Execute_ArchetypeCardsService_Update()
        {
            // Arrange
            var article = new UnexpandedArticle {
                Title = "Clear Wing", Url = "/wiki/List_of_\"Clear_Wing\"_cards"
            };

            _config.WikiaDomainUrl.Returns("http://yugioh.wikia.com");
            _archetypeService.ArchetypeByName(Arg.Any <string>()).Returns(new Archetype());
            _archetypeWebPage.Cards(Arg.Any <Uri>()).Returns(new List <string> {
                "Blue-Eyes White Dragon"
            });
            _archetypeCardsService.Update(Arg.Any <UpdateArchetypeCardsCommand>()).Returns((IEnumerable <ArchetypeCard>)null);

            // Act
            await _sut.ProcessItem(article);

            // Assert
            await _archetypeCardsService.Received(1).Update(Arg.Any <UpdateArchetypeCardsCommand>());
        }
コード例 #22
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            var yugiohCard = _cardWebPage.GetYugiohCard(new Uri(new Uri(_config.WikiaDomainUrl), item.Url));

            if (yugiohCard != null)
            {
                var card = await _yugiohCardService.AddOrUpdate(yugiohCard);

                if (card != null)
                {
                    response.IsSuccessfullyProcessed = true;
                }
            }

            return(response);
        }
コード例 #23
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            if (!item.Title.Equals("Archetype", StringComparison.OrdinalIgnoreCase))
            {
                var archetypeUrl = new Uri(new Uri(_config.WikiaDomainUrl), item.Url);

                var thumbNailUrl = await _archetypeWebPage.ArchetypeThumbnail(item.Id, item.Url);

                var existingArchetype = await _archetypeService.ArchetypeById(item.Id);

                var archetype = existingArchetype == null
                    ? await _archetypeService.Add(new AddArchetypeCommand
                {
                    ArchetypeNumber = item.Id,
                    Name            = item.Title,
                    ImageUrl        = ImageHelper.ExtractImageUrl(thumbNailUrl),
                    ProfileUrl      = archetypeUrl.AbsoluteUri
                })
                    : await _archetypeService.Update(new UpdateArchetypeCommand
                {
                    Id         = existingArchetype.Id,
                    Name       = item.Title,
                    ImageUrl   = ImageHelper.ExtractImageUrl(thumbNailUrl),
                    ProfileUrl = archetypeUrl.AbsoluteUri
                });


                if (archetype != null)
                {
                    response.IsSuccessfullyProcessed = true;
                }
            }

            return(response);
        }
コード例 #24
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };

            var card = await _cardService.CardByName(item.Title);

            if (card != null)
            {
                var tipSections = new List <CardTipSection>();

                var articleCardTips = await _wikiArticle.Simple(item.Id);

                foreach (var cardTipSection in articleCardTips.Sections)
                {
                    var tipSection = new CardTipSection
                    {
                        Name = cardTipSection.Title,
                        Tips = SectionHelper.GetSectionContentList(cardTipSection)
                    };


                    if (cardTipSection.Title.Equals("List", StringComparison.OrdinalIgnoreCase) ||
                        cardTipSection.Title.Equals("Lists", StringComparison.OrdinalIgnoreCase))
                    {
                        tipSection.Name = tipSection.Tips.First();
                        tipSection.Tips.Clear();
                        _tipRelatedWebPage.GetTipRelatedCards(tipSection, item);
                    }

                    tipSections.Add(tipSection);
                }

                await _cardTipService.Update(card.Id, tipSections);
            }

            return(response);
        }
コード例 #25
0
        public void GetTipRelatedCards(CardTipSection section, UnexpandedArticle item)
        {
            if (section == null)
            {
                throw new ArgumentNullException(nameof(section));
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var tipWebPage = new HtmlWeb().Load(_config.WikiaDomainUrl + item.Url);

            //Get tip related card list url
            var cardListUrl = _tipRelatedHtmlDocument.GetUrl(tipWebPage);

            //get tips related card list table
            var cardListTable = _tipRelatedHtmlDocument.GetTable(tipWebPage);

            GetTipRelatedCards(section, cardListUrl, cardListTable);
        }
コード例 #26
0
        public async Task Given_An_Invalid_Banlist_Article_Should_Not_Execute_WikiArticle_Simple_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 _wikiArticle.DidNotReceive().Simple(Arg.Any <int>());
        }
コード例 #27
0
        public async Task <ArticleTaskResult> ProcessItem(UnexpandedArticle item)
        {
            var response = new ArticleTaskResult {
                Article = item
            };
            var archetypeName = StringHelpers.ArchetypeNameFromListTitle(item.Title);

            var archetypeUrl = new Uri(new Uri(_config.WikiaDomainUrl), item.Url);

            var existingArchetype = await _archetypeService.ArchetypeByName(archetypeName);

            if (existingArchetype != null)
            {
                var archetype = await _archetypeCardsService.Update(new UpdateArchetypeCardsCommand { ArchetypeId = existingArchetype.Id, Cards = _archetypeWebPage.Cards(archetypeUrl) });

                if (archetype != null)
                {
                    response.IsSuccessfullyProcessed = true;
                }
            }

            return(response);
        }
コード例 #28
0
 public Task <ArticleTaskResult> Process(string category, UnexpandedArticle article)
 {
     _logger.Info("{1} | ' {0} '", article.Title, category);
     return(_articleProcessor.Process(category, article));
 }
コード例 #29
0
 public Task Publish(UnexpandedArticle article)
 {
     return(_queue.Publish(article));
 }
コード例 #30
0
        public Task <ArticleTaskResult> Process(string category, UnexpandedArticle article)
        {
            var handler = _articleItemProcessors.Single(h => h.Handles(category));

            return(handler.ProcessItem(article));
        }