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>()); }
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>()); }
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(); }
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; } }
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); }
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); }
public Task Publish(UnexpandedArticle article) { var messageToBeSent = new Article { Id = article.Id, CorrelationId = Guid.NewGuid() }; return(_queue.Publish(messageToBeSent)); }
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(); }
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)); }
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)); }
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(); }
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(); }
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>()); }
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>()); }
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(); }
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>()); }
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>()); }
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); }
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); }
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); }
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); }
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>()); }
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); }
public Task <ArticleTaskResult> Process(string category, UnexpandedArticle article) { _logger.Info("{1} | ' {0} '", article.Title, category); return(_articleProcessor.Process(category, article)); }
public Task Publish(UnexpandedArticle article) { return(_queue.Publish(article)); }
public Task <ArticleTaskResult> Process(string category, UnexpandedArticle article) { var handler = _articleItemProcessors.Single(h => h.Handles(category)); return(handler.ProcessItem(article)); }