public async Task Given_A_Valid_ArticleList_Collection_Should_Increment_Processed_Variable_If_Article_Is_Processed_Successfully() { // Arrange const int expected = 2; var fixture = new Fixture { RepeatCount = 3 }; var articles = fixture.Create <UnexpandedArticle[]>(); _articleProcessor .Process("some category", Arg.Any <UnexpandedArticle>()) .ReturnsForAnyArgs ( x => new ArticleTaskResult { IsSuccessfullyProcessed = true }, x => new ArticleTaskResult { IsSuccessfullyProcessed = true }, x => new ArticleTaskResult() ); // Act var result = await _sut.Process("a category", articles); // Assert result.Processed.Should().Be(expected); }
public async Task Given_A_banlistType_Should_Invoke_Process_Method_Twice() { // Arrange const int expected = 2; _banlistUrlDataSource .GetBanlists(Arg.Any <BanlistType>(), Arg.Any <string>()) .Returns ( new Dictionary <int, List <int> > { [2017] = new List <int> { 1, 2 } } ); _articleProcessor .Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>()) .Returns(new ArticleTaskResult { IsSuccessfullyProcessed = true }); // Act await _sut.Process(BanlistType.Tcg); // Assert await _articleProcessor.Received(expected).Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>()); }
public async Task Given_A_Category_And_A_Article_Should_Invoke_LogInformation_Method_Twice() { // Arrange const int expected = 2; _articleProcessor.Process(Arg.Any <string>(), Arg.Any <UnexpandedArticle>()).Returns(new ArticleTaskResult()); // Act await _sut.Process("category", new UnexpandedArticle()); // Assert _logger.Received(expected).Log(LogLevel.Information, Arg.Any <EventId>(), Arg.Any <object>(), Arg.Any <Exception>(), Arg.Any <Func <object, Exception, string> >()); }
public async Task <CardInformationConsumerResult> Handle(CardInformationConsumer request, CancellationToken cancellationToken) { var cardInformationResult = new CardInformationConsumerResult(); var validationResults = _validator.Validate(request); if (validationResults.IsValid) { var article = JsonConvert.DeserializeObject <Article>(request.Message); _logger.LogInformation("Processing category {@Category} '{@Title}'", request.Category, article.Title); var results = await _articleProcessor.Process(request.Category, article); _logger.LogInformation("Finished processing category {@Category} '{@Title}'", request.Category, article.Title); if (!results.IsSuccessful) { cardInformationResult.Errors.AddRange(results.Errors); } } else { cardInformationResult.Errors = validationResults.Errors.Select(err => err.ErrorMessage).ToList(); } return(cardInformationResult); }
private ProcessedArticle GetProcessedArticle(string url) { IArticle unprocessedArticle = _articleProvider.Get(url); ProcessedArticle result = _articleProcessor.Process(unprocessedArticle); return(result); }
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 <ArticleBatchTaskResult> Process(string category, UnexpandedArticle[] articles) { if (string.IsNullOrWhiteSpace(category)) { throw new ArgumentException(nameof(category)); } if (articles == null) { throw new ArgumentException(nameof(articles)); } var response = new ArticleBatchTaskResult(); foreach (var article in articles) { try { var result = await _articleProcessor.Process(category, article); if (result.IsSuccessfullyProcessed) { response.Processed += 1; } } catch (Exception ex) { response.Failed.Add(new ArticleException { Article = article, Exception = ex }); } } return(response); }
public async Task <ArticleBatchTaskResult> Process(BanlistType banlistType) { var response = new ArticleBatchTaskResult(); const string baseBanlistUrl = "http://yugioh.fandom.com/wiki/July_1999_Lists"; var banListArticleIds = _banlistUrlDataSource.GetBanlists(banlistType, baseBanlistUrl); foreach (var(year, banlistIds) in banListArticleIds) { _logger.LogInformation("{@BanlistType} banlists for the year: {@Year}", banlistType.ToString().ToUpper(), year); foreach (var articleId in banlistIds) { _logger.LogInformation("{@BanlistType} banlist articleId: {@ArticleId}", banlistType.ToString().ToUpper(), articleId); var articleResult = await _articleProcessor.Process(ArticleCategory.ForbiddenAndLimited, new UnexpandedArticle { Id = articleId }); if (articleResult.IsSuccessfullyProcessed) { response.Processed += 1; } } } return(response); }
public async Task Given_A_Valid_CardInformationConsumer_IsSuccessful_Should_Be_True() { // Arrange var cardInformationConsumer = new CardInformationConsumer { Category = "category", Message = "{\"Id\":703544,\"CorrelationId\":\"3e2bf3ca-d903-440c-8cd5-be61c95ae1fc\",\"Title\":\"Tenyi\",\"Url\":\"https://yugioh.fandom.com/wiki/Card_Tips:Tenyi\"}" }; _validator.Validate(Arg.Any <CardInformationConsumer>()) .Returns(new CardInformationConsumerValidator().Validate(cardInformationConsumer)); _articleProcessor.Process(Arg.Any <string>(), Arg.Any <Article>()).Returns(new ArticleTaskResult()); // Act var result = await _sut.Handle(cardInformationConsumer, CancellationToken.None); // Assert result.IsSuccessful.Should().BeTrue(); }
public async Task Given_An_Valid_BanlistInformationConsumer_IsSuccessful_Should_BeTrue() { // Arrange var banlistInformationConsumer = new BanlistInformationConsumer { Message = $"{{\"Id\":16022,\"CorrelationId\":\"0606a974-ea5f-436b-a263-ee638762e019\",\"Title\":\"Historic Forbidden/Limited Chart\",\"Url\":null}}" }; _validator .Validate(Arg.Is(banlistInformationConsumer)) .Returns(new BanlistInformationConsumerValidator().Validate(banlistInformationConsumer)); _articleProcessor.Process(Arg.Any <Article>()) .Returns(new ArticleConsumerResult { IsSuccessfullyProcessed = true }); // Act var result = await _sut.Handle(banlistInformationConsumer, CancellationToken.None); // Assert result.IsSuccessful.Should().BeTrue(); }
public async Task Given_An_Valid_CardInformationConsumer_IsSuccessful_Should_BeTrue() { // Arrange var cardInformationConsumer = new CardInformationConsumer { Message = "{\"Id\":10917,\"Title\":\"Amazoness Archer\",\"Url\":\"https://yugioh.fandom.com/wiki/Amazoness_Archer\"}" }; _validator .Validate(Arg.Is(cardInformationConsumer)) .Returns(new CardInformationConsumerValidator().Validate(cardInformationConsumer)); _articleProcessor.Process(Arg.Any <Article>()) .Returns(new ArticleConsumerResult { IsSuccessfullyProcessed = true }); // Act var result = await _sut.Handle(cardInformationConsumer, CancellationToken.None); // Assert result.ArticleConsumerResult.IsSuccessfullyProcessed.Should().BeTrue(); }
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 <CardInformationConsumerResult> Handle(CardInformationConsumer request, CancellationToken cancellationToken) { var cardInformationTaskResult = new CardInformationConsumerResult(); var validationResults = _validator.Validate(request); if (validationResults.IsValid) { var cardArticle = JsonConvert.DeserializeObject <Article>(request.Message); var results = await _articleProcessor.Process(cardArticle); cardInformationTaskResult.ArticleConsumerResult = results; } return(cardInformationTaskResult); }
public async Task <BanlistInformationConsumerResult> Handle(BanlistInformationConsumer request, CancellationToken cancellationToken) { var response = new BanlistInformationConsumerResult(); var validationResults = _validator.Validate(request); if (validationResults.IsValid) { var banlistArticle = JsonConvert.DeserializeObject <Article>(request.Message); var results = await _articleProcessor.Process(banlistArticle); if (!results.IsSuccessfullyProcessed) { response.Errors.Add(results.Failed.Exception.Message); } response.Message = request.Message; } return(response); }
public Task <ArticleTaskResult> Process(string category, UnexpandedArticle article) { _logger.Info("{1} | ' {0} '", article.Title, category); return(_articleProcessor.Process(category, article)); }