public void EditComment_BannedDomain() { var user = TestHelper.SetPrincipal("TestUser02"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); var editCmd = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!").SetUserContext(user); var editResult = editCmd.Execute().Result; VoatAssert.IsValid(editResult, Status.Denied, "Expecting Denied Status"); Assert.AreEqual("Comment contains banned domains", editResult.Message); }
public void EditComment_Empty() { var user = TestHelper.SetPrincipal("TestUser11"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); var editCmd = new EditCommentCommand(c.Response.ID, " ").SetUserContext(user); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, editResult.Message); Assert.AreEqual("Empty comments not allowed", editResult.Message); }
public void EditComment_WrongOwner() { var user = TestHelper.SetPrincipal("TestUser15"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); user = TestHelper.SetPrincipal("TestUser12"); var editCmd = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!").SetUserContext(user); var editResult = editCmd.Execute().Result; VoatAssert.IsValid(editResult, Status.Denied); Assert.AreEqual("User does not have permissions to perform requested action", editResult.Message); }
public void EditComment_WrongOwner() { TestHelper.SetPrincipal("TestUser15"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it."); var c = cmd.Execute().Result; Assert.IsTrue(c.Success, c.Message); TestHelper.SetPrincipal("TestUser12"); var editCmd = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!"); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, editResult.Message); Assert.AreEqual("User doesn't have permissions to perform requested action", editResult.Message); }
public void EditComment_BannedDomain() { TestHelper.SetPrincipal("TestUser2"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it."); var c = cmd.Execute().Result; Assert.IsTrue(c.Success); var editCmd = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!"); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, "Edit command with banned domain returned true"); Assert.AreEqual(Status.Denied, editResult.Status, "expecting denied status"); Assert.AreEqual("Comment contains banned domains", editResult.Message); }
public async Task <ActionResult> EditComment([FromBody()] CommentEditInput commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content).SetUserContext(User); var result = await cmd.Execute(); if (!result.Success) { PreventSpamAttribute.Reset(HttpContext); } return(JsonResult(result)); } else { PreventSpamAttribute.Reset(HttpContext); return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); } }
public async Task Comment_Length_Validations() { var user = TestHelper.SetPrincipal("TestUser20"); var createCmd = new CreateCommentCommand(1, null, "Can you hear me now?".RepeatUntil(10001)).SetUserContext(user); var r = await createCmd.Execute(); VoatAssert.IsValid(r, Status.Denied); createCmd = new CreateCommentCommand(1, null, "Can you hear me now?").SetUserContext(user); r = await createCmd.Execute(); VoatAssert.IsValid(r); var editCmd = new EditCommentCommand(r.Response.ID, "Can you hear me now?".RepeatUntil(100001)).SetUserContext(user); r = await editCmd.Execute(); VoatAssert.IsValid(r, Status.Denied); }
public async Task EditComment() { string content = "This is data [howdy](http://www.howdy.com)"; var user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new EditCommentCommand(1, content).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); Assert.AreEqual(content, r.Response.Content); Assert.AreEqual(Formatting.FormatMessage(content), r.Response.FormattedContent); //verify using (var db = new Voat.Data.Repository(user)) { var comment = await db.GetComment(1); Assert.IsNotNull(comment.LastEditDate); Assert.AreEqual(cmd.Content, comment.Content); } }
public void EditComment() { string content = "This is data [howdy](http://www.howdy.com)"; TestHelper.SetPrincipal("unit"); var cmd = new EditCommentCommand(1, content); var r = cmd.Execute().Result; Assert.IsTrue(r.Success); Assert.AreEqual(content, r.Response.Content); Assert.AreEqual(Formatting.FormatMessage(content), r.Response.FormattedContent); //verify using (var db = new Voat.Data.Repository()) { var comment = db.GetComment(1); Assert.IsNotNull(comment.LastEditDate); Assert.AreEqual(cmd.Content, comment.Content); } }
public async Task <ActionResult> EditComment([Bind(Include = "ID, Content")] Data.Models.Comment commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content); var result = await cmd.Execute(); if (result.Success) { return(Json(new { response = result.Response.FormattedContent })); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // var existingComment = _db.Comments.Find(commentModel.ID); // if (existingComment != null) // { // if (existingComment.UserName.Trim() == User.Identity.Name && !existingComment.IsDeleted) // { // bool containsBannedDomain = BanningUtility.ContentContainsBannedDomain(existingComment.Submission.Subverse, commentModel.Content); // if (containsBannedDomain) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Comment contains links to banned domain(s)."); // } // existingComment.LastEditDate = Repository.CurrentDate; // existingComment.Content = commentModel.Content; // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) // { // existingComment.Content = ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPreSave, existingComment); // } // //save fully formatted content // var formattedComment = Voat.Utilities.Formatting.FormatMessage(existingComment.Content); // existingComment.FormattedContent = formattedComment; // await _db.SaveChangesAsync(); // //HACK: Update comment in cache - to be replaced with EditCommentCommand in future // string key = CachingKey.CommentTree(existingComment.SubmissionID.Value); // if (CacheHandler.Instance.Exists(key)) // { // CacheHandler.Instance.Replace<usp_CommentTree_Result>(key, existingComment.ID, x => { // x.Content = existingComment.Content; // x.FormattedContent = existingComment.FormattedContent; // return x; // }); // } // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) // { // ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPostSave, existingComment); // } // //return the formatted comment so that it can replace the existing html comment which just got modified // return Json(new { response = formattedComment }); // } // return Json("Unauthorized edit.", JsonRequestBehavior.AllowGet); // } //} //if (Request.IsAjaxRequest()) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //return Json("Unauthorized edit or comment not found - comment ID was.", JsonRequestBehavior.AllowGet); }