예제 #1
0
        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");
        }
예제 #2
0
        // [HttpPost]
        public ActionResult SaveUpdate(GroupUpdateFormModel newupdate)
        {
            if (ModelState.IsValid)
            {
                GroupUpdate update = Mapper.Map<GroupUpdateFormModel, GroupUpdate>(newupdate);
                var userId = User.Identity.GetUserId();
                groupUpdateService.CreateUpdate(update, userId);
                var Updates = Mapper.Map<IEnumerable<GroupUpdate>, IEnumerable<GroupUpdateViewModel>>(groupUpdateService.GetUpdatesByGoal(newupdate.GroupGoalId));
                foreach (var item in Updates)
                {
                    item.IsSupported = groupUpdateSupportService.IsUpdateSupported(item.GroupUpdateId, User.Identity.GetUserId(), groupUserService);
                    item.UserId = groupUpdateUserService.GetGroupUpdateUser(item.GroupUpdateId).Id;
                }
                GroupUpdateListViewModel updates = new GroupUpdateListViewModel()
                {
                    GroupUpdates = Updates,
                    Metric = groupGoalService.GetGroupGoal(newupdate.GroupGoalId).Metric,
                    Target = groupGoalService.GetGroupGoal(newupdate.GroupGoalId).Target
                };
                return PartialView("_UpdateView", updates);

            }
            return null;
        }
예제 #3
0
        public void Save_Update_Update_Mandatory_Test()
        {
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);

            // The MVC pipeline doesn't run, so binding and validation don't run. 
            controller.ModelState.AddModelError("", "mock error message");
            GroupUpdateFormModel update = new GroupUpdateFormModel();
            update.Updatemsg = string.Empty;
            var result = controller.SaveUpdate(update) as RedirectToRouteResult;

            Assert.IsNull(result);
        }