public async Task Given_An_ArchetypeMessage_If_Archetype_Is_Not_Found_Should_Not_Invoke_Update_Method() { // Arrange var archetypeMessage = new ArchetypeMessage(); // Act await _sut.Process(archetypeMessage); // Assert await _archetypeService.DidNotReceive().Update(Arg.Any <Archetype>()); }
public async Task Given_An_ArchetypeMessage_If_Archetype_Is_Found_Should_Not_Invoke_Add_Method() { // Arrange var archetypeMessage = new ArchetypeMessage(); _archetypeService.ArchetypeById(Arg.Any <long>()).Returns(new Archetype { Id = 42432, Name = "Blue-Eyes" }); // Act await _sut.Process(archetypeMessage); // Assert await _archetypeService.DidNotReceive().Add(Arg.Any <Archetype>()); }
public async Task Given_An_ArchetypeMessage_With_An_ImageUrl_Should_Invoke_Publish_Method() { // Arrange var archetypeMessage = new ArchetypeMessage { ImageUrl = "https://vignette.wikia.nocookie.net/yugioh/images/3/3d/DMx001_Triple_Blue-Eyes.png/revision/latest/scale-to-width-down/350?cb=20140404164917" }; _archetypeService.ArchetypeById(Arg.Any <long>()).Returns(new Archetype { Id = 42432, Name = "Blue-Eyes" }); // Act await _sut.Process(archetypeMessage); // Assert await _archetypeImageQueueService.Received(1).Publish(Arg.Any <DownloadImage>()); }
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); }