public void TestCommentDelete() { var authorCommentID = CommentIDs.Item1; var modCommentID = CommentIDs.Item2; //read content, ensure data is correct VerifyComment(authorCommentID, CONTENT, false); VerifyComment(modCommentID, CONTENT, false); //delete comment (mod) var user = TestHelper.SetPrincipal(AUTHOR_NAME); var d = new DeleteCommentCommand(authorCommentID).SetUserContext(user); var r = d.Execute().Result; Assert.IsTrue(r.Success, r.Message); user = TestHelper.SetPrincipal(MOD_NAME); d = new DeleteCommentCommand(modCommentID, "My Reason Here").SetUserContext(user);; r = d.Execute().Result; Assert.IsTrue(r.Success, r.Message); //read comment, ensure data exists VerifyComment(authorCommentID, "Deleted", true); VerifyComment(modCommentID, "Deleted", true); }
private dynamic DeleteComment(DeleteCommentCommand deletePostCommand) { _commandInvokerFactory.Handle <DeleteCommentCommand, CommandResult>(deletePostCommand); string returnURL = Request.Headers.Referrer; return(Response.AsRedirect(returnURL)); }
public async Task <ActionResult> ModeratorDelete(string subverse, int submissionID, ModeratorDeleteContentViewModel model) { var q = new QueryComment(model.ID); var comment = await q.ExecuteAsync(); if (comment == null || comment.SubmissionID != submissionID) { ModelState.AddModelError("", "Can not find comment. Who did this?"); return(View(new ModeratorDeleteContentViewModel())); } if (!ModeratorPermission.HasPermission(User.Identity.Name, comment.Subverse, Domain.Models.ModeratorAction.DeleteComments)) { return(new HttpUnauthorizedResult()); } if (!ModelState.IsValid) { return(View(model)); } var cmd = new DeleteCommentCommand(model.ID, model.Reason); var r = await cmd.Execute(); if (r.Success) { return(RedirectToRoute("SubverseCommentsWithSort_Short", new { subverseName = subverse, submissionID = submissionID })); } else { ModelState.AddModelError("", r.Message); return(View(model)); } }
public async Task DeleteComment_Moderator() { //Assert.Inconclusive("Complete this test"); var content = "This is my data too you know 2"; var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, content).SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; //switch to mod of sub user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new DeleteCommentCommand(id, "This is spam").SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); //Content should remain unchanged in mod deletion Assert.AreEqual(comment.Content, content); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(content)); } }
public void DeleteComment_Owner() { //Assert.Inconclusive("Complete this test"); var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know").SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; var cmd = new DeleteCommentCommand(id).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); Assert.AreNotEqual(c.Response.Content, comment.Content); //Ensure content is replaced in moderator deletion Assert.IsTrue(comment.Content.StartsWith("Deleted by")); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(comment.Content)); } }
public async Task ShouldDeleteArticleComment() { await Helper.EnsureUserIsCreatedAndSetInDatabaseContext(); var articleDto = await Helper.CreateDefaultArticle_ReturnDefaultArticleDto(); await Helper.CreateDefaultComment(articleDto.Slug); var originalArticleWithComment = await Helper.QueryDefaultArticleDto(); Assert.AreEqual(1, originalArticleWithComment.Comments.Count); var commentId = originalArticleWithComment.Comments.First().CommentId; var deleteCommand = new DeleteCommentCommand { Slug = originalArticleWithComment.Slug, CommentId = commentId }; await SliceFixture.ExecuteDbContextAsync(async (ctx, mediator) => { await mediator.Send(deleteCommand); }); var resultArticleWithComment = await Helper.QueryDefaultArticleDto(); var resultCommentsCount = resultArticleWithComment.Comments.Count; Assert.AreEqual(0, resultCommentsCount); }
public async Task <DeleteCommentByIdResponse> Handle(DeleteCommentByIdRequest request, CancellationToken cancellationToken) { if (request.AuthenticatorRole == AppRole.Employee) { return(new DeleteCommentByIdResponse() { Error = new ErrorModel(ErrorType.Unauthorized) }); } var query = new GetCommentQuery() { Id = request.CommentId }; var comment = await queryExecutor.Execute(query); if (comment == null) { return(new DeleteCommentByIdResponse() { Error = new ErrorModel(ErrorType.NotFound) }); } var command = new DeleteCommentCommand() { Parameter = comment }; var deletedComment = await commandExecutor.Execute(command); return(new DeleteCommentByIdResponse { Data = deletedComment }); }
public void DeleteComment() { TestHelper.SetPrincipal("TestUser1"); var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know"); var c = cmdcreate.Execute().Result; Assert.IsNotNull(c, "response null"); Assert.IsTrue(c.Success, c.Message); Assert.IsNotNull(c.Response, "Response payload null"); int id = c.Response.ID; var cmd = new DeleteCommentCommand(id); var r = cmd.Execute().Result; Assert.IsTrue(r.Success); //verify using (var db = new Voat.Data.Repository()) { var comment = db.GetComment(id); Assert.AreEqual(true, comment.IsDeleted); Assert.AreNotEqual(c.Response.Content, comment.Content); } }
public IHttpActionResult DeleteComment(int id) { var command = new DeleteCommentCommand { intIdComment = id }; _mediator.Send(command); return(Ok(command)); }
public void Handle(DeleteCommentCommand command) { //TODO: the deleteComment needs optmistic lock -> add lesson version!! //Lesson lesson = repo.GetById<Lesson>(command.Id, command.Version); Lesson lesson = repo.GetById <Lesson>(command.Id); lesson.DeleteComment(command.CommentId, command.Date); repo.Save(lesson, Guid.NewGuid()); }
public async Task DeleteCommentAsync(long commentId) { var command = new DeleteCommentCommand { CommentId = commentId }; await pipelineService.HandleCommandAsync(command); }
public async Task <IActionResult> Delete( [FromRoute] Guid id, [FromRoute] Guid articleId, CancellationToken ct = default) { var command = new DeleteCommentCommand(id, articleId); await Mediator.Send(command, ct); return(NoContent()); }
public async Task <ActionResult> Delete(int id, DeleteCommentCommand command) { if (id != command.Id && id != Author.Id) { return(BadRequest()); } await _mediator.Send(command); return(NoContent()); }
public ResultDto DeleteComment(long postId, long commentId) { return(Result(() => { var command = new DeleteCommentCommand { PostId = postId, CommentId = commentId, }; CommandDispatcher.Send(command); })); }
public ActionResult DeleteComment(int id, [FromServices] DeleteCommentCommand delCommentcmd) { var model = new DeleteCommentModel(); model.Id = id; var comment = _dataContext.Comments .Include(c => c.MediaItem) .FirstOrDefault(c => c.Id == id); delCommentcmd.Execute(model); return(RedirectToAction("Details", new { id = comment.MediaItem.Id })); }
public void ReturnInstance_WhenCalled() { // Arrange var contextMock = new Mock <IMotorSystemContext>(); var providerMock = new Mock <ICommentInputProvider>(); // Act var command = new DeleteCommentCommand(contextMock.Object, providerMock.Object); // Assert Assert.IsNotNull(command); }
public void Handler_GivenInvalidCommentId_ThrowsException() { // Arrange var invalidCommentId = 99; // Act var command = new DeleteCommentCommand { Id = invalidCommentId }; var handler = new DeleteCommentCommand.DeleteCommentCommandHandler(Context); // Assert Should.ThrowAsync <NotFoundException>(() => handler.Handle(command, CancellationToken.None)); }
public async Task <ActionResult> DeleteComment(int id) { if (ModelState.IsValid) { var cmd = new DeleteCommentCommand(id, "This feature is not yet implemented").SetUserContext(User); var result = await cmd.Execute(); return(base.JsonResult(result)); } else { return(base.JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
public async Task GivenValidRequest_WhenTheCommentExistsAndIsOwnerByTheRequest_DeletesCommentSuccessfully() { // Arrange var deleteCommentCommand = new DeleteCommentCommand(1, "how-to-train-your-dragon"); var existingComment = Context.Comments.Find(1); existingComment.ShouldNotBeNull(); // Act var handler = new DeleteCommentCommandHandler(Context, CurrentUserContext); var response = await handler.Handle(deleteCommentCommand, CancellationToken.None); // Assert Context.Comments.Find(1).ShouldBeNull(); }
public async Task GivenValidRequest_WhenTheCommentIsNotOwnedByTheRequester_ThrowsApiExceptionForForbidden() { // Arrange var deleteCommentCommand = new DeleteCommentCommand(2, "how-to-train-your-dragon"); // Act var handler = new DeleteCommentCommandHandler(Context, CurrentUserContext); var response = await Should.ThrowAsync <ConduitApiException>(async() => { await handler.Handle(deleteCommentCommand, CancellationToken.None); }); // Assert response.StatusCode.ShouldBe(HttpStatusCode.Forbidden); }
public async Task GivenValidRequest_WhenTheArticleDoesNotExist_ThrowsApiExceptionForNotFound() { // Arrange var deleteCommentCommand = new DeleteCommentCommand(1, "how-to-not-train-your-dragon"); // Act var handler = new DeleteCommentCommandHandler(Context, CurrentUserContext); var response = await Should.ThrowAsync <ConduitApiException>(async() => { await handler.Handle(deleteCommentCommand, CancellationToken.None); }); // Assert response.StatusCode.ShouldBe(HttpStatusCode.NotFound); }
public async Task Handler_GivenValidCommentId_ShouldRemoveComment() { // Arrange var validCommentId = 3; // Act var command = new DeleteCommentCommand { Id = validCommentId }; var handler = new DeleteCommentCommand.DeleteCommentCommandHandler(Context); await handler.Handle(command, CancellationToken.None); // Assert var entity = Context.Comments.Find(command.Id); entity.ShouldBeNull(); }
private void InvalidateCommands() { EditFeeScheuleCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); PrintCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); EditAttributeCommand.RaiseCanExecuteChanged(); DeleteAttributeCommand.RaiseCanExecuteChanged(); DeleteFeeScheuleCommand.RaiseCanExecuteChanged(); NewOrderCommand.RaiseCanExecuteChanged(); EditContactCommand.RaiseCanExecuteChanged(); DeleteContactCommand.RaiseCanExecuteChanged(); EditEmployeeCommand.RaiseCanExecuteChanged(); DeleteEmployeeCommand.RaiseCanExecuteChanged(); EditCommentCommand.RaiseCanExecuteChanged(); DeleteCommentCommand.RaiseCanExecuteChanged(); }
public async Task <IActionResult> Delete(int id = default, string returnUrl = default) { if (id != default) { var commentCommand = new DeleteCommentCommand { Id = id }; await _mediator.Send(commentCommand); } if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl)) { return(RedirectToAction("Index", "Posts")); } else { return(Redirect(returnUrl)); } }
public ICommandResult Handle(DeleteCommentCommand command) { //Fail Fast Validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, Messages.Ex_ExceptionGeneric, command.Notifications)); } var comment = _repository.GetById(command.Id); if (comment == null) { return(new GenericCommandResult(false, Messages.Ex_ItemNotFound.ToFormat(command.Id.ToString() ?? ""), command.Notifications)); } _repository.Delete(comment); return(new GenericCommandResult(true, Messages.Act_Deleted, comment)); }
private CommandResponse ExecuteDeleteComment(DeleteCommentCommand command) { foreach (var q in Questions) { var existingComment = q.Comments.SingleOrDefault(c => c.Id == command.CommentId); if (existingComment != null) { q.Comments.Remove(existingComment); return(CommandResponse.Success()); } foreach (var a in q.Answers) { existingComment = a.Comments.SingleOrDefault(c => c.Id == command.CommentId); if (existingComment != null) { a.Comments.Remove(existingComment); return(CommandResponse.Success()); } } } return(CommandResponse.Failure($"Comment with id {command.CommentId} does not exist.")); }
private dynamic DeleteComment(DeleteCommentCommand deletePostCommand) { _commandInvokerFactory.Handle<DeleteCommentCommand, CommandResult>(deletePostCommand); string returnURL = Request.Headers.Referrer; return Response.AsRedirect(returnURL); }
public async Task Bug_Trap_Positive_ContributionPoints_Removed() { //Test that when a user deletes comments and submissions with positive points, that the points are reset var altList = new[] { "UnitTestUser10", "UnitTestUser11", "UnitTestUser12", "UnitTestUser13", "UnitTestUser14", "UnitTestUser15" }; var primaryUser = "******"; var currentUser = TestHelper.SetPrincipal(primaryUser); var cmdSubmission = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Title = "Test Positive SCP Removed upon Delete", Content = "Does this get removed?", Subverse = "unit" }).SetUserContext(currentUser); var subResponse = await cmdSubmission.Execute(); VoatAssert.IsValid(subResponse); var submissionID = subResponse.Response.ID; var cmdComment = new CreateCommentCommand(submissionID, null, "This is my manipulation comment. Upvote. Go.").SetUserContext(currentUser); var commentResponse = await cmdComment.Execute(); VoatAssert.IsValid(commentResponse); var commentID = commentResponse.Response.ID; var vote = new Func <int, Domain.Models.ContentType, string[], Task>(async(id, contentType, users) => { foreach (string user in users) { var userIdentity = TestHelper.SetPrincipal(user); switch (contentType) { case Domain.Models.ContentType.Comment: var c = new CommentVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var cr = await c.Execute(); VoatAssert.IsValid(cr); break; case Domain.Models.ContentType.Submission: var s = new SubmissionVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var sr = await s.Execute(); VoatAssert.IsValid(sr); break; } } }); await vote(commentID, Domain.Models.ContentType.Comment, altList); var deleteComment = new DeleteCommentCommand(commentID).SetUserContext(currentUser); var deleteCommentResponse = await deleteComment.Execute(); VoatAssert.IsValid(deleteCommentResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.CommentVoteTracker.Where(x => x.CommentID == commentID); Assert.AreEqual(altList.Length, votes.Count()); var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found comment votes with a non-zero vote value"); } await vote(submissionID, Domain.Models.ContentType.Submission, altList); var deleteSubmission = new DeleteSubmissionCommand(submissionID).SetUserContext(currentUser); var deleteSubmissionResponse = await deleteSubmission.Execute(); VoatAssert.IsValid(deleteSubmissionResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.SubmissionVoteTracker.Where(x => x.SubmissionID == submissionID); Assert.AreEqual(altList.Length + 1, votes.Count()); //author has a vote var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found submission votes with a non-zero vote value"); } }
/// <summary> /// Delete comment command handler async /// </summary> /// <param name="commentCommand">Delete comment command.</param> /// <param name="commentRepository">Comment repository.</param> public async Task HandleDeleteCommentAsync(DeleteCommentCommand commentCommand) { await commentRepository.DeleteCommentAsync(commentCommand.CommentId); }
public async Task <ActionResult> DeleteComments(DeleteCommentCommand command) { return(Ok(await Mediator.Send(command))); }
public async Task <ActionResult <string> > DeleteComment([FromQuery] DeleteCommentCommand command) { var result = await Mediator.Send(command); return(new JsonResult(result)); }