public async Task <ArchetypeInformationConsumerResult> Handle(ArchetypeInformationConsumer request, CancellationToken cancellationToken) { var archetypeInformationConsumerResult = new ArchetypeInformationConsumerResult(); var validationResults = _validator.Validate(request); if (validationResults.IsValid) { var archetypeArticle = JsonConvert.DeserializeObject <ArchetypeMessage>(request.Message); _logger.LogInformation("Processing archetype '{@Title}'", archetypeArticle.Name); var results = await _archetypeProcessor.Process(archetypeArticle); _logger.LogInformation("Finished processing archetype '{@Title}'", archetypeArticle.Name); if (!results.IsSuccessful) { archetypeInformationConsumerResult.Errors.AddRange(results.Errors); } } else { archetypeInformationConsumerResult.Errors = validationResults.Errors.Select(err => err.ErrorMessage).ToList(); } return(archetypeInformationConsumerResult); }
public async Task Given_A_Valid_ArchetypeInformationConsumer_IsSuccessful_Should_Be_True() { // Arrange var archetypeInformationConsumer = new ArchetypeInformationConsumer { Message = "{\"Id\":703544,\"CorrelationId\":\"3e2bf3ca-d903-440c-8cd5-be61c95ae1fc\",\"Title\":\"Tenyi\",\"Url\":\"https://yugioh.fandom.com/wiki/Tenyi\"}" }; _validator.Validate(Arg.Any <ArchetypeInformationConsumer>()) .Returns(new ArchetypeInformationConsumerValidator().Validate(archetypeInformationConsumer)); _archetypeProcessor.Process(Arg.Any <ArchetypeMessage>()).Returns(new ArchetypeDataTaskResult <ArchetypeMessage>()); // Act var result = await _sut.Handle(archetypeInformationConsumer, CancellationToken.None); // Assert result.IsSuccessful.Should().BeTrue(); }