public async Task <IActionResult> Respond(BoardRespondViewModel vm, IFormFile file) { var thread = boardRepo.BoardThreads.FirstOrDefault(t => t.Id == vm.ThreadId); await googleRecaptchaHelper.VerifyRecaptcha(Request, ModelState); if (MaxImagesCountReached(thread)) { ModelState.AddModelError("maxImgCountError", "Maksimalni broj slika u dretvi premašen."); } if (ModelState.IsValid) { if (IsImageFileValid(file)) { vm.BoardPost.Image = await writer.UploadImage(file); } vm.BoardPost.Text = vm.BoardPost.Text.Trim(); boardRepo.AddPostToThread(vm.BoardPost, vm.ThreadId); ModelState.Clear(); TempData["ScrollToComment"] = true; return(RedirectToAction("Thread", "Board", new { thread.Id })); } else { return(Thread(thread.Id)); } }
public async Task Respond_ThreadId_DisplaysThreadViewWithCorrectModel(BoardThread[] boardThreads) { var boardController = GetMockBoardController(boardThreads); var respondViewModel = new BoardRespondViewModel { ThreadId = 1, BoardPost = new BoardPost { Text = "", Image = "" } }; var result = (RedirectToActionResult)await boardController.Respond(respondViewModel, null); Assert.True(result.RouteValues.ContainsKey("Id")); result.RouteValues.TryGetValue("Id", out object id); Assert.Equal(1L, id); }
public async Task Respond_ThreadId_RedirectsToThread() { var boardController = GetMockBoardController(new BoardThread[] { new BoardThread { Id = 1, ImageCount = 0 } }); var respondViewModel = new BoardRespondViewModel { ThreadId = 1, BoardPost = new BoardPost { Text = "", Image = "" } }; var result = (RedirectToActionResult)await boardController.Respond(respondViewModel, null); Assert.Equal("Thread", result.ActionName); Assert.Equal("Board", result.ControllerName); }