public async Task TestAddsComment() { var existing = await _movieRepository.GetMovieAsync(_movieId); var numberOfComments = existing.Comments.Count; var commentText = "I do not think this movie means what you think it means."; try { var result = await AddCommentToMovieAsync(commentText); var okResult = (OkObjectResult)result; Assert.AreEqual(200, okResult.StatusCode); var comments = (CommentResponse)okResult.Value; Assert.AreEqual(numberOfComments + 1, comments.Comments.Count); this._commentId = comments.Comments.First().Id; await GetMovieAndVerifyChanges(commentText, numberOfComments); } catch (Exception ex) { await _commentRepository.DeleteCommentAsync(new ObjectId(_movieId), _commentId, _opinionatedUser); Assert.Fail(ex.Message); } finally { await Cleanup(); } }
public async Task <ActionResult> DeleteCommentAsync([FromBody] MovieCommentInput input) { var movieId = new ObjectId(input.MovieId); var commentId = new ObjectId(input.CommentId); var user = await UserController.GetUserFromTokenAsync(_userRepository, Request); var result = await _commentsRepository.DeleteCommentAsync(movieId, commentId, user); return(result != null ? (ActionResult)Ok(new CommentResponse( result.Comments.OrderByDescending(d => d.Date).ToList())) : BadRequest(new CommentResponse())); }
public async Task <IActionResult> Delete(string userName, string title, int id) { try { if (GetClaimByName(SUB) != (await _commentsRepository.GetCommentByIdAsync(userName, title, id)).Author) { return(BadRequest()); } if (await _commentsRepository.DeleteCommentAsync(userName, title, id)) { return(Ok()); } } catch (Exception e) { _logger.LogError($"Error while updating comment\n {e.Message}"); } return(BadRequest()); }
public async Task Cleanup() { await _commentRepository.DeleteCommentAsync(new ObjectId(_movieId), _commentId, _opinionatedUser); }
public async Task <IActionResult> DeletePost([FromBody] Comment comment) { return(Ok(await _commentsRepository.DeleteCommentAsync(comment.Id))); }