Пример #1
0
 public ActionResult EditUpdate(UpdateFormModel newupdate)
 {
     Update update = Mapper.Map<UpdateFormModel, Update>(newupdate);
     if (ModelState.IsValid)
     {
         update.Goal = goalService.GetGoal(newupdate.GoalId);
         updateService.EditUpdate(update);
         var Updates = Mapper.Map<IEnumerable<Update>, IEnumerable<UpdateViewModel>>(updateService.GetUpdatesByGoal(newupdate.GoalId));
         foreach (var item in Updates)
         {
             item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
         }
         UpdateListViewModel updates = new UpdateListViewModel()
         {
             Updates = Updates,
             Metric = goalService.GetGoal(newupdate.GoalId).Metric,
             Target = goalService.GetGoal(newupdate.GoalId).Target
         };
         return PartialView("_UpdateView", updates);
     }
     return null;
 }
Пример #2
0
        public void Edit_Update_Post()
        {
            MemoryUser user = new MemoryUser("adarsh");
            ApplicationUser applicationUser = new ApplicationUser()
            {
                Activated = true,
                Email = "*****@*****.**",
                FirstName = "Adarsh",
                LastName = "Vikraman",
                RoleId = 0
            };
            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());

            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);

            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<UpdateFormModel, Update>();
            Mapper.CreateMap<Update, UpdateViewModel>();

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

            IEnumerable<Update> updt = new List<Update> {
            new Update { UpdateId =1, Updatemsg = "t1",GoalId =1},
             new Update { UpdateId =2, Updatemsg = "t2",GoalId =1},
              new Update { UpdateId =3, Updatemsg = "t3",GoalId =2},

              }.AsEnumerable();
            updateRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Update, bool>>>())).Returns(updt);
            UpdateFormModel mock = new UpdateFormModel();
            mock.Updatemsg = "mock";
            mock.GoalId = 1;
            mock.status = 34;
            PartialViewResult result = controller.EditUpdate(mock) as PartialViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(UpdateListViewModel),
            result.ViewData.Model, "Wrong View Model");
        }
Пример #3
0
        public ActionResult SaveUpdate(UpdateFormModel newupdate)
        {
            // Update update = Mapper.Map<UpdateFormModel, Update>(newupdate);
            if (ModelState.IsValid)
            {
                Update update = Mapper.Map<UpdateFormModel, Update>(newupdate);
                update.Goal = goalService.GetGoal(newupdate.GoalId);
                var updateVal = updateService.GetHighestUpdateValue(newupdate.GoalId);
               
                if(updateVal!=null)
                {  
                    if (updateVal.status <= newupdate.status)
                    {
                        updateService.CreateUpdate(update);
                       
                    }
                    else
                    {
                        update.status = -1;
                        ModelState.AddModelError(update.Updatemsg, "cannot enter");
                    }
                }
                else
                {
                    updateService.CreateUpdate(update);
                }


                     var Updates = Mapper.Map<IEnumerable<Update>, IEnumerable<UpdateViewModel>>(updateService.GetUpdatesByGoal(newupdate.GoalId));
                     foreach (var item in Updates)
                     {
                         item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
                     }
                     UpdateListViewModel updates = new UpdateListViewModel()
                     {
                         Updates = Updates,
                         Metric = goalService.GetGoal(newupdate.GoalId).Metric,
                         Target = goalService.GetGoal(newupdate.GoalId).Target,
                         //IsSupported = updateSupportService.IsUpdateSupported(newupdate.UpdateId,((SocialGoalUser)(User.Identity)).UserId)
                     };
                     return PartialView("_UpdateView", updates);

            }
            return null;
        }
Пример #4
0
        public void Save_Update_Update_Mandatory_Test()
        {
            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);

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

            Assert.IsNull(result);
        }