public async Task Given_An_Existing_Archetype_Article_Should_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.Update(Arg.Any <UpdateArchetypeCommand>()).Returns(new Archetype()); _archetypeService.ArchetypeById(Arg.Any <int>()).Returns(new Archetype()); // Act await _sut.ProcessItem(article); // Assert await _archetypeService.Received(1).Update(Arg.Any <UpdateArchetypeCommand>()); }
public async Task <ArchetypeDataTaskResult <ArchetypeMessage> > Process(ArchetypeMessage archetypeData) { var articleDataTaskResult = new ArchetypeDataTaskResult <ArchetypeMessage> { ArchetypeData = archetypeData }; var existingArchetype = await _archetypeService.ArchetypeById(archetypeData.Id); if (existingArchetype == null) { var newArchetype = new Archetype { Id = archetypeData.Id, Name = archetypeData.Name, Url = archetypeData.ProfileUrl, Created = DateTime.UtcNow, Updated = archetypeData.Revision }; await _archetypeService.Add(newArchetype); } else { existingArchetype.Name = archetypeData.Name; existingArchetype.Url = archetypeData.ProfileUrl; existingArchetype.Updated = archetypeData.Revision; await _archetypeService.Update(existingArchetype); } if (!string.IsNullOrWhiteSpace(archetypeData.ImageUrl)) { var downloadImage = new DownloadImage { RemoteImageUrl = new Uri(archetypeData.ImageUrl), ImageFileName = archetypeData.Id.ToString(), }; await _archetypeImageQueueService.Publish(downloadImage); } return(articleDataTaskResult); }
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); }