public ActionResult EditFocus(FocusFormModel focusFormViewModel)
 {
     Focus focus = Mapper.Map<FocusFormModel, Focus>(focusFormViewModel);
     focus.Group = groupService.GetGroup(focus.GroupId);
     var errors = focusService.CanAddFocus(focus).ToList();
     ModelState.AddModelErrors(errors);
     if (ModelState.IsValid)
     {
         focusService.UpdateFocus(focus);
         focusService.SaveFocus();
         return RedirectToAction("Index", new { id = focus.GroupId });
     }
     return View("EditFocus", focusFormViewModel);
 }
        public ActionResult CreateFocus(FocusFormModel focus)
        {
            var errors = focusService.CanAddFocus(Mapper.Map<FocusFormModel, Focus>(focus)).ToList();

            ModelState.AddModelErrors(errors);
            if (ModelState.IsValid)
            {
                Focus newFocus = Mapper.Map<FocusFormModel, Focus>(focus);
                focusService.CreateFocus(newFocus);
                //var createdfocus = focusService.GetFocus(focus.FocusName);
                return RedirectToAction("Focus", new { id = newFocus.FocusId });
            }
            return View("CreateFocus", focus);
        }
        public void Focus_Description_Mandatory()
        {
            // Arrange                    
            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");

            // Act          
            Mapper.CreateMap<FocusFormModel, Focus>();
            FocusFormModel focus = new FocusFormModel();
            focus.Description = string.Empty;
            var result = (ViewResult)controller.CreateFocus(focus);

            // Assert - check that we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
            Assert.AreEqual("CreateFocus", result.ViewName);
        }
        public void Create_Focus()
        {
            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());
            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);
            principal.Setup(x => x.Identity).Returns(goalsetterUser);




            FocusFormModel focus = new FocusFormModel();
            focus.GroupId = 1;
            focus.FocusName = "t";
            focus.Description = "t";
            Focus mock = new Focus()
            {
                FocusName = "x",
                FocusId = 2,
                Description = "t",
                GroupId = 1
            };

            //Create Mapping 
            Mapper.CreateMap<FocusFormModel, Focus>();


            // Act
            var result = (RedirectToRouteResult)controller.CreateFocus(focus);
            Assert.AreEqual("Focus", result.RouteValues["action"]);


        }
        public void Edit_Focus_Post()
        {
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);

            // Act
            Mapper.CreateMap<FocusFormModel, Focus>();
            FocusFormModel group = new FocusFormModel()
            {
                FocusId = 1,
                FocusName = "test",
                Description = "test",
                GroupId = 1


            };

            Group grp = new Group()
            {
                GroupId = 1,
                GroupName = "t",
                Description = "t"
            };
            groupRepository.Setup(x => x.GetById(1)).Returns(grp);
            var result = (RedirectToRouteResult)controller.EditFocus(group);
            Assert.AreEqual("Index", result.RouteValues["action"]);

        }