public void DisplayComments()
        {
            IEnumerable<Comment> cmnt = new List<Comment> {

            new Comment { CommentId =1, UpdateId = 1,CommentText="x"},
            new Comment { CommentId =2, UpdateId = 1,CommentText="y"},
            new Comment { CommentId =3, UpdateId = 1,CommentText="z"},

              }.AsEnumerable();

            commentRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Comment, bool>>>())).Returns(cmnt);
            CommentUser cmtuser = new CommentUser()
            {
                CommentId = 1,
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                CommentUserId = 1
            };
            commentUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<CommentUser, bool>>>())).Returns(cmtuser);

            ApplicationUser applicationUser = new ApplicationUser()
            {
                Activated = true,
                Email = "*****@*****.**",
                FirstName = "Adarsh",
                LastName = "Vikraman",
                RoleId = 0
            };
            userRepository.Setup(x => x.GetById("402bd590-fdc7-49ad-9728-40efbfe512ec")).Returns(applicationUser);
            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);

            Mapper.CreateMap<Comment, CommentsViewModel>();
            PartialViewResult rslt = controller.DisplayComments(1) as PartialViewResult;
            Assert.IsNotNull(rslt, "View Result is null");
            Assert.IsInstanceOf(typeof(IEnumerable<CommentsViewModel>),
             rslt.ViewData.Model, "Wrong View Model");
            var cmntsView = rslt.ViewData.Model as IEnumerable<CommentsViewModel>;
            Assert.AreEqual(3, cmntsView.Count(), "Got wrong number of Comments");
        }
Example #2
0
 public void CreateComment(Comment comment, string userId)
 {
     commentRepository.Add(comment);
     SaveComment();
     var commentUser = new CommentUser { UserId = userId, CommentId = comment.CommentId };
     commentUserRepository.Add(commentUser);
     SaveComment();
 }