public void ShouldAddAndRemoveArticleComment() { PopulateRepository(); #region Add AddArticleCommentCommand addCommand = new AddArticleCommentCommand { ArticleId = new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e"), Body = "hELLO Im COmMeNtIng hERe!!" }; applicationService.AddComment(addCommand); Article article = applicationService.GetById(new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e")); Assert.AreEqual(1, article.Comments.Count()); #endregion #region Remove RemoveArticleCommentCommand removeCommand = new RemoveArticleCommentCommand { ArticleId = new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e"), CommentId = article.Comments.First().Id }; applicationService.RemoveComment(removeCommand); Assert.AreEqual(1, article.Comments.Count()); #endregion }
public void ShouldFailAddAndRemoveArticleCommentDifferentUser() { PopulateRepository(); #region Add AddArticleCommentCommand addCommand = new AddArticleCommentCommand { ArticleId = new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e"), Body = "hELLO IN COmMeNtIng hERe!!" }; applicationService.AddComment(addCommand); Article article = applicationService.GetById(new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e")); Assert.AreEqual(1, article.Comments.Count()); #endregion //REFRESH USER ID identityResolver.RefreshId(); //NOW IT'S LIKE A DIFFERENT USER #region Remove RemoveArticleCommentCommand removeCommand = new RemoveArticleCommentCommand { ArticleId = new Guid("4aeabf09-da78-4fcd-bb73-667605871a5e"), CommentId = article.Comments.First().Id }; applicationService.RemoveComment(removeCommand); Assert.AreEqual("Erro na remoção", domainNotificationHandler.GetNotifications().First().Title); #endregion }
public void RemoveComment(RemoveArticleCommentCommand command) { command.Validate(); if (AddNotifications(command)) { return; } Article article = _articleRepository.GetById(command.ArticleId); LedgerIdentityUser user = _identityResolver.GetUser(); if (NotifyNullArticle(article)) { return; } Comment comment = article.Comments.FirstOrDefault(c => c.Id == command.CommentId); if (comment == null || comment.AuthorId != user.Id) { AddNotification("Erro na remoção", "Não foi possível remover esse comentário."); return; } _articleRepository.Update(article); Commit(); }
public IActionResult Remove(Guid id, [FromBody] RemoveArticleCommentCommand command) { command.ArticleId = id; _articleAppService.RemoveComment(command); return(CreateResponse()); }