public void CreateUpdate(GroupUpdate update, string userId)
 {
     groupUpdateRepository.Add(update);
     SaveUpdate();
     var groupUpdateUser = new GroupUpdateUser { UserId = userId, GroupUpdateId = update.GroupUpdateId };
     groupUpdateUserRepository.Add(groupUpdateUser);
     SaveUpdate();
 }
 public void CreateGroupUpdateUser(string userId, int groupUpdateId)
 {
     var groupUpdateUser = new GroupUpdateUser { UserId = userId, GroupUpdateId = groupUpdateId };
     groupUpdateUserRepository.Add(groupUpdateUser);
     SaveGroupUpdateUser();
 }
        public void Edit_Update_Post()
        {
            MemoryUser user = new MemoryUser("adarsh");
            ApplicationUser applicationUser = getApplicationUser();
            var userContext = new UserInfo
            {
                UserId = user.Id,
                DisplayName = user.UserName,
                UserIdentifier = applicationUser.Email,
                RoleName = Enum.GetName(typeof(UserRoles), applicationUser.RoleId)
            };
            var testTicket = new FormsAuthenticationTicket(
                1,
                user.Id,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userContext.ToString());


            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);

            principal.SetupGet(x => x.Identity.Name).Returns("adarsh");
            controllerContext.SetupGet(x => x.HttpContext.User).Returns(principal.Object);
            controllerContext.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);
            controller.ControllerContext = controllerContext.Object;

            contextBase.SetupGet(x => x.Request).Returns(httpRequest.Object);
            contextBase.SetupGet(x => x.Response).Returns(httpResponse.Object);
            genericPrincipal.Setup(x => x.Identity).Returns(identity.Object);

            contextBase.SetupGet(a => a.Response.Cookies).Returns(new HttpCookieCollection());

            var formsAuthentication = new DefaultFormsAuthentication();
            formsAuthentication.SetAuthCookie(contextBase.Object, testTicket);

            HttpCookie authCookie = contextBase.Object.Response.Cookies[FormsAuthentication.FormsCookieName];

            var ticket = formsAuthentication.Decrypt(authCookie.Value);
            var goalsetterUser = new SocialGoalUser(ticket);
            string[] userRoles = { goalsetterUser.RoleName };

            principal.Setup(x => x.Identity).Returns(goalsetterUser);
            //GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
            Mapper.CreateMap<GroupUpdateFormModel, GroupUpdate>();
            Mapper.CreateMap<GroupUpdate, GroupUpdateViewModel>();

            Metric fakeMetric = new Metric()
            {
                MetricId = 1,
                Type = "%"
            };
            GroupGoal goal = new GroupGoal()
            {
                Metric = fakeMetric,
                Target = 100,
                GroupGoalId = 1
            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);


            IEnumerable<GroupUpdate> updt = new List<GroupUpdate> {            
            new GroupUpdate { GroupUpdateId =1, Updatemsg = "t1",GroupGoalId =1},
             new GroupUpdate { GroupUpdateId =2, Updatemsg = "t2",GroupGoalId =1},
              new GroupUpdate { GroupUpdateId =3, Updatemsg = "t3",GroupGoalId =2},
            
          }.AsEnumerable();
            groupUdateRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupUpdate, bool>>>())).Returns(updt);

            GroupUser grpuser = new GroupUser()
            {
                GroupUserId = 1,
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            groupUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(grpuser);

            GroupUpdateUser updtuser = new GroupUpdateUser()
            {
                GroupUpdateId = 1,
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            groupUpdateUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUpdateUser, bool>>>())).Returns(updtuser);
            GroupUpdateFormModel mock = new GroupUpdateFormModel();
            mock.Updatemsg = "mock";
            mock.GroupGoalId = 1;
            mock.status = 34;
            PartialViewResult result = controller.EditUpdate(mock) as PartialViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(GroupUpdateListViewModel),
            result.ViewData.Model, "Wrong View Model");
        }