public async Task EmptyContent() { var comment = new CommentSubmittionModel("guid"); comment.Comment.Content = " "; comment.Comment.Title = "Title"; var result = await Controller.SubmitComment(comment) as HttpStatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, 400); }
public async Task ModelStateError() { var comment = new CommentSubmittionModel("guid") {Comment = {Content = "content", Title = ""}}; PageServiceMock.Setup(f => f.GetPageByIdAsync("guid")).ReturnsAsync(new Page()); Controller.ModelState.AddModelError("test", "test"); var result = await Controller.SubmitComment(comment) as HttpStatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(400, result.StatusCode); }
public async Task<ActionResult> SubmitComment(CommentSubmittionModel model) { if (string.IsNullOrWhiteSpace(model.PageId) || !ModelState.IsValid) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); var result = await _pageService.GetPageByIdAsync(model.PageId); if (result == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); await _pageService.AddCommentAsync(model.Comment.Title, model.Comment.Content, User, result); return RedirectToAction("Show", "Page", new { id = model.PageId }); }
public async Task AddComment() { var page = new Page(); PageServiceMock.Setup(f => f.GetPageByIdAsync("guid")) .ReturnsAsync(page); var comment = new CommentSubmittionModel("guid"); comment.Comment.Content = "some content"; comment.Comment.Title = "titlehere"; var result = await Controller.SubmitComment(comment) as RedirectToRouteResult; Assert.IsNotNull(result); PageServiceMock.Verify(f => f.AddCommentAsync("titlehere", "some content", It.IsAny<IPrincipal>(), page)); }
public async Task NonExistingPage() { PageServiceMock.Setup(f => f.GetPageByIdAsync("boo")) .ReturnsAsync(null); var comment = new CommentSubmittionModel("boo"); comment.Comment.Content = "Hello"; comment.Comment.Title = "Title"; var result = await Controller.SubmitComment(comment) as HttpStatusCodeResult; Assert.IsNotNull(result); Assert.AreEqual(result.StatusCode, 400); }