public IEnumerable<ValidationResult> CanAddGoal(GroupGoal newGoal,IGroupUpdateService groupUpdateService)
        {
            GroupGoal goal;
            if (newGoal.GroupGoalId == 0)
                goal = GroupGoalRepository.Get(g => (g.GroupId == newGoal.GroupId) && (g.GoalName == newGoal.GoalName));
            else
                goal = GroupGoalRepository.Get(g => (g.GroupId == newGoal.GroupId) && (g.GoalName == newGoal.GoalName) && g.GroupGoalId != newGoal.GroupGoalId);
            if (goal != null)
            {
                yield return new ValidationResult("GoalName", Resources.GoalExists);
            }
            if (newGoal.StartDate.Subtract(newGoal.EndDate).TotalSeconds > 0)
            {
                yield return new ValidationResult("EndDate", Resources.EndDate);
            }
            int flag = 0;
            int status = 0;
            if (newGoal.GroupGoalId != 0)
            {
                var Updates = groupUpdateService.GetUpdatesByGoal(newGoal.GroupGoalId).OrderByDescending(g => g.UpdateDate).ToList();

                if (Updates.Count() > 0)
                {
                    if (Updates[0].UpdateDate.Subtract(newGoal.EndDate).TotalSeconds > 0)
                    {
                        flag = 1;
                    }
                    if (newGoal.StartDate.Subtract(Updates[0].UpdateDate).TotalSeconds > 0)
                    {
                        status = 1;
                    }
                    if (flag == 1)
                    {
                        
                        yield return new ValidationResult("EndDate", Resources.EndDateNotValid + " " + Updates[0].UpdateDate.ToString("dd-MMM-yyyy"));
                    }
                    else if (status == 1)
                    {                        
                        yield return new ValidationResult("StartDate", Resources.StartDate + " " + Updates[0].UpdateDate.ToString("dd-MMM-yyyy"));
                    }

                }
            }
        }
        public void Delete_Goal_Get_ReturnsView()
        {


            GroupGoal fake = new GroupGoal()
            {
                GroupGoalId = 1,
                GoalName = "test",
                Description = "test",
                GroupId = 1,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                GoalStatusId = 1,
                GroupUserId = 2

            };


            groupGoalRepository.Setup(x => x.GetById(1)).Returns(fake);

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            ViewResult result = controller.DeleteGoal(1) as ViewResult;
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(GroupGoal),
                 result.ViewData.Model, "Wrong View Model");
            var group = result.ViewData.Model as GroupGoal;
            Assert.AreEqual("test", group.Description, "Got wrong Focus Description");

        }
        public void Group_Goal_Page_View()
        {
            //Arrange 
            GroupUser grpUser = new GroupUser()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            GroupGoal goal = new GroupGoal()
            {
                GroupGoalId = 1,
                GoalName = "t",
                GoalStatusId = 1,
                Description = "x",
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                GroupUser = grpUser

            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);

            ApplicationUser user = new ApplicationUser()
            {
                Id = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<ApplicationUser, bool>>>())).Returns(user);
            IEnumerable<GoalStatus> fake = new List<GoalStatus> {
            new GoalStatus { GoalStatusId =1, GoalStatusType ="Inprogress"},
            new GoalStatus { GoalStatusId =2, GoalStatusType ="OnHold"},
         
          }.AsEnumerable();
            goalStatusRepository.Setup(x => x.GetAll()).Returns(fake);

            Mapper.CreateMap<GroupGoal, GroupGoalViewModel>();
            //Act
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            ViewResult result = controller.GroupGoal(1) as ViewResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(typeof(GroupGoalViewModel), result.ViewData.Model, "WrongType");
            var data = result.ViewData.Model as GroupGoalViewModel;
            Assert.AreEqual("t", data.GoalName);
        }
        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");
        }
        public void Get_GoalReport_Test()
        {
            GroupGoal goal = new GroupGoal()
            {
                GoalStatusId = 1,
                GroupGoalId = 1
            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            JsonResult reslt = controller.GetGoalReport(1) as JsonResult;
            Assert.IsNotNull(reslt);

        }
        public void Goal_Status_Post_Test()
        {
            GoalStatus status = new GoalStatus()
            {
                GoalStatusId = 1,
                GoalStatusType = "InProgress"
            };
            GroupGoal goal = new GroupGoal()
            {
                GroupId = 1,
                GroupGoalId = 1,
                GoalStatusId = 1,
                GoalStatus = status

            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            string result = controller.GoalStatus(1, 1) as string;
            Assert.AreEqual("InProgress", result);
        }
        public void Delete_Goal_Post()
        {
            GroupUser user = new GroupUser()
            {
                GroupId = 1
            };
            GroupGoal goal = new GroupGoal()
            {
                GroupGoalId = 1,
                GroupId = 1,
                GoalName = "t",
                Description = "t",
                GroupUser = user
            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            var result = controller.DeleteConfirmed(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["action"]);

        }
        public void Edit_Goal_Get_View()
        {
            GroupUser user = new GroupUser()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                GroupId = 1,
                GroupUserId = 1,
                Admin = false

            };
            GroupGoal goal = new GroupGoal()
            {
                GroupGoalId = 1,
                GroupId = 1,
                GoalName = "t",
                Description = "t",
                GoalStatusId = 1,
                GroupUserId = 1,
                GroupUser = user,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
            };
            groupGoalRepository.Setup(x => x.GetById(1)).Returns(goal);
            IEnumerable<Focus> fakeFocus = new List<Focus> 
            {
            new Focus { FocusId = 1, FocusName="Test1",GroupId = 1},
             new Focus { FocusId = 2, FocusName="Test2",GroupId = 1},
            new Focus { FocusId = 3, FocusName="Test3",GroupId = 1}
          }.AsEnumerable();
            focusRepository.Setup(x => x.GetMany(p => p.GroupId.Equals(1))).Returns(fakeFocus);

            IEnumerable<Metric> fakeMatrices = new List<Metric> 
            {
                new Metric{MetricId=1, Type="Test1"},
                new Metric{MetricId=2,Type="Test2"},
                new Metric{MetricId=3,Type="Test3"}
            }.AsEnumerable();

            metricRepository.Setup(x => x.GetAll()).Returns(fakeMatrices);

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            Mapper.CreateMap<GroupGoal, GroupGoalFormModel>();
            ViewResult result = controller.EditGoal(1) as ViewResult;
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(GroupGoalFormModel),
                result.ViewData.Model, "Wrong View Model");
        }
 public void CreateGroupGoal(GroupGoal GroupGoal)
 {
     GroupGoalRepository.Add(GroupGoal);
     SaveGroupGoal();
 }
 public void EditGroupGoal(GroupGoal groupGoalToEdit)
 {
     GroupGoalRepository.Update(groupGoalToEdit);
     SaveGroupGoal();
 }