public async Task <IHttpActionResult> Get(int id) { try { var review = await _reviewOperations.GetAsync(id); if (review == null) { return(this.Result404("This review is not found")); } var result = Mapper.Map <ReviewViewModelGet>(review); var picture = (await _pictureOperations.GetByLinkedObject(LinkedObjectType.User, review.User.Id)).FirstOrDefault(); var pictureViewModel = Mapper.Map <PictureViewModelGet>(picture); if (pictureViewModel != null) { pictureViewModel.Url = Url.Content($"~/api/picture/{pictureViewModel.Id}"); result.User.Picture = pictureViewModel; } return(Ok(result)); } catch (Exception ex) { ErrorLogger.Log("CANNOT GET REVIEW", ex); throw; } }
public void Get_Ok_Test() { var review = _context.Reviews.Include(r => r.User).First(); var result = _reviewOperations.GetAsync(review.Id).Result; Assert.AreEqual(review.Text, result.Text); Assert.AreEqual(review.User.Name, review.User.Name); }