public ActionResult ReactionOverview(int id) { int userId = int.Parse(User.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.Sid).Value); List <ReactionViewModel> reactionViews = new List <ReactionViewModel>(); if (_reactionLogic.GetAllCommentsWithQuestionId(id).Count > 0) { foreach (Reaction reaction in _reactionLogic.GetAllCommentsWithQuestionId(id)) { reactionViews.Add(new ReactionViewModel(reaction, _questionLogic.GetSingleQuestion(reaction.QuestionId), _userLogic.GetUserById(userId))); } ViewBag.Message = null; return(View("Reaction/Overview", reactionViews)); } TempData["ErrorMessage"] = "Vraag heeft geen reacties"; return(RedirectToAction("Overviewclosed")); }
public void GetAllCommentsWithQuestionId() { Mock <IReactionContext> mockContext = new Mock <IReactionContext>(); Mock <Category> category = new Mock <Category>("Medisch"); Mock <Question> question = new Mock <Question>(1, "foo", "baa", Question.QuestionStatus.Open, DateTime.Today, true, category.Object, 12); List <Reaction> mockList = new List <Reaction>(); mockContext.Setup(x => x.GetAllReactions(question.Object.QuestionId)) .Returns(mockList); ReactionLogic reactionLogic = new ReactionLogic(mockContext.Object); List <Reaction> result = reactionLogic.GetAllCommentsWithQuestionId(question.Object.QuestionId); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(List <Reaction>)); mockContext.Verify(x => x.GetAllReactions(1), Times.Exactly(1)); }