public void DisplayComments() { IEnumerable<GroupComment> cmnt = new List<GroupComment> { new GroupComment { GroupCommentId =1, GroupUpdateId = 1,CommentText="x"}, new GroupComment { GroupCommentId =2, GroupUpdateId = 1,CommentText="y"}, new GroupComment { GroupCommentId =3, GroupUpdateId = 1,CommentText="z"}, }.AsEnumerable(); groupCommentRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupComment, bool>>>())).Returns(cmnt); GroupCommentUser gcuser = new GroupCommentUser() { GroupCommentId = 1, GroupCommentUserId = 1, UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; groupCommentUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupCommentUser, bool>>>())).Returns(gcuser); ApplicationUser applicationUser = getApplicationUser(); userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<ApplicationUser, bool>>>())).Returns(applicationUser); GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService); Mapper.CreateMap<GroupComment, GroupCommentsViewModel>(); PartialViewResult rslt = controller.DisplayComments(1) as PartialViewResult; Assert.IsNotNull(rslt, "View Result is null"); Assert.IsInstanceOf(typeof(IEnumerable<GroupCommentsViewModel>), rslt.ViewData.Model, "Wrong View Model"); var cmntsView = rslt.ViewData.Model as IEnumerable<GroupCommentsViewModel>; Assert.AreEqual(3, cmntsView.Count(), "Got wrong number of Comments"); }