示例#1
0
 public void EditGoal(Goal goalToEdit)
 {
     goalRepository.Update(goalToEdit);
     SaveGoal();
 }
示例#2
0
        public IEnumerable<ValidationResult> CanAddGoal(Goal newGoal, IUpdateService updateService)
        {
            Goal goal;
            if (newGoal.GoalId == 0)
                goal = goalRepository.Get(g => g.GoalName == newGoal.GoalName);
            else
                goal = goalRepository.Get(g => g.GoalName == newGoal.GoalName && g.GoalId != newGoal.GoalId);
            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.GoalId != 0)
            {
                var Updates = updateService.GetUpdatesByGoal(newGoal.GoalId).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"));
                    }
                }
               

                
            }
        }
示例#3
0
        public void Index()
        {
            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)
            };

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

            var testTicket = new FormsAuthenticationTicket(
                1,
                user.Id,
                DateTime.Now,
                DateTime.Now.Add(FormsAuthentication.Timeout),
                false,
                userContext.ToString());

            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);
            Goal goal = new Goal()
            {
                GoalId = 1,
                GoalName = "t",
                GoalStatusId = 1,
                Desc = "x",
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1)

            };
            goalRepository.Setup(x => x.GetById(1)).Returns(goal);
            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<Goal, GoalViewModel>();

            ViewResult result = controller.Index(1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(typeof(GoalViewModel), result.ViewData.Model, "WrongType");
            var data = result.ViewData.Model as GoalViewModel;
            Assert.AreEqual("t", data.GoalName);
        }
示例#4
0
 public void CreateGoal(Goal goal)
 {
     goalRepository.Add(goal);
     SaveGoal();
 }
示例#5
0
 public void Get_GoalReport_Test()
 {
     Goal goal = new Goal()
     {
         GoalStatusId = 1,
         GoalId = 1
     };
     goalRepository.Setup(x => x.GetById(1)).Returns(goal);
     GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
     JsonResult reslt = controller.GetGoalReport(1) as JsonResult;
     Assert.IsNotNull(reslt);
 }
示例#6
0
 public void Goal_Status_Post_Test()
 {
     GoalStatus status = new GoalStatus()
     {
         GoalStatusId = 1,
         GoalStatusType = "InProgress"
     };
     Goal goal = new Goal()
     {
         GoalId = 1,
         GoalStatus = status,
         GoalStatusId = 1
     };
     goalRepository.Setup(x => x.GetById(1)).Returns(goal);
     GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
     string result = controller.GoalStatus(1, 1) as string;
     Assert.AreEqual("InProgress", result);
 }
示例#7
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");
        }
示例#8
0
        public void Edit_Goal_Get_View()
        {
            Goal goal = new Goal()
            {
                GoalId = 1,
                GoalName = "t",
                Desc = "t",
                GoalStatusId = 1,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
            };
            goalRepository.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);

            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
            Mapper.CreateMap<Goal, GoalFormModel>();
            ViewResult result = controller.Edit(1) as ViewResult;
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(GoalFormModel),
                result.ViewData.Model, "Wrong View Model");
            var data = result.ViewData.Model as GoalFormModel;
            Assert.AreEqual("t", data.Desc);
        }
示例#9
0
        public void Delete_Goal_Post()
        {
            Goal goal = new Goal()
            {
                GoalId = 1,
                GoalName = "t",
                Desc = "t"

            };
            goalRepository.Setup(x => x.GetById(1)).Returns(goal);
            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
            var result = controller.DeleteConfirmed(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
示例#10
0
        public void Delete_Goal_Get_ReturnsView()
        {
            Goal fake = new Goal()
            {
                GoalId = 1,
                GoalName = "test",
                Desc = "test",
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                GoalStatusId = 1,

            };

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

            GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
            ViewResult result = controller.Delete(1) as ViewResult;
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(Goal),
                 result.ViewData.Model, "Wrong View Model");
            var group = result.ViewData.Model as Goal;
            Assert.AreEqual("test", group.Desc, "Got wrong Focus Description");
        }
示例#11
0
 public void Support_Invite_View_Returns_Test()
 {
     Goal goal = new Goal()
     {
         GoalStatusId = 1,
         GoalId = 1
     };
     goalRepository.Setup(x => x.GetById(1)).Returns(goal);
     GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService);
     PartialViewResult result = controller.SupportInvitation(1) as PartialViewResult;
     Assert.IsNotNull(result);
     Assert.IsInstanceOf(typeof(Goal),
        result.ViewData.Model, "Wrong View Model");
 }