public IActionResult SearchByTags([FromQuery] string[] tag) { try { string email = HttpContext.User.Claims.First().Value; List <Tag> tags = new List <Tag>(); foreach (string t in tag) { tags.Add(Tag.ByName(t)); } return(Ok(Photos.SearchByTags(email, tags).ConvertAll(p => PhotoModel.ToModel(p)))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public void SearchByTags() { List <string> tags = new List <string>(); tags.Add("Cat"); tags.Add("Feline"); List <Tag> tagsList = new List <Tag>(); tagsList.Add(Tag.ByName("Cat")); tagsList.Add(Tag.ByName("Feline")); GoogleServices.SetupSequence(g => g.UploadImage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())); GoogleServices.SetupSequence(g => g.GetImageURL(It.IsAny <string>())) .Returns("https://storage.googleapis.com/example"); GoogleServices.SetupSequence(g => g.GetImageTags(It.IsAny <string>())) .Returns(tags); User user = SessionLogic.SignUp(User()); Photo photo = UserLogic.AddPhoto(user.Email, Photo(), "<encodedImageInBase64>"); List <Photo> returnedPhotos = PhotoLogic.SearchByTags(user.Email, tagsList); Assert.AreEqual(returnedPhotos[0], photo); }