public async Task <IActionResult> TagPhotos([FromBody] BatchUpdateTags updateTags) { if (!ModelState.IsValid) { return(BadRequest(new ProblemModel(ModelState))); } await _photoSevice.UpdatePhotoTags(updateTags.PhotoIds, updateTags.GetAddedTagNames(), updateTags.GetRemovedTagIds()); return(Ok()); }
public async Task UpdatePhotoTags() { var photoIds = _fixture.CreateMany <int>(5); var tagStates = _fixture.CreateMany <TagState>(5); var batchUpdate = new BatchUpdateTags { PhotoIds = photoIds.ToList(), TagStates = tagStates.ToList() }; _photosService.Setup(m => m.UpdatePhotoTags(It.IsAny <List <int> >(), It.IsAny <List <string> >(), It.IsAny <List <int> >())); var response = await _tagsController.TagPhotos(batchUpdate); _photosService.Verify(m => m.UpdatePhotoTags(It.IsAny <List <int> >(), It.IsAny <List <string> >(), It.IsAny <List <int> >()), Times.Once); Assert.IsType <OkResult>(response); }
public async Task UpdatePhotoTagsInvalid() { var photoIds = _fixture.CreateMany <int>(5); var tagStates = _fixture.CreateMany <TagState>(5); var batchUpdate = new BatchUpdateTags { PhotoIds = photoIds.ToList(), TagStates = tagStates.ToList() }; _photosService.Setup(m => m.UpdatePhotoTags(It.IsAny <List <int> >(), It.IsAny <List <string> >(), It.IsAny <List <int> >())); _tagsController.ModelState.AddModelError("key", "message"); var response = await _tagsController.TagPhotos(batchUpdate); _photosService.Verify(m => m.UpdatePhotoTags(It.IsAny <List <int> >(), It.IsAny <List <string> >(), It.IsAny <List <int> >()), Times.Never); Assert.IsType <BadRequestObjectResult>(response); }