public ActionResult AddGroupUser()
 {
     Guid groupIdToken = (Guid)TempData["grToken"];
     var groupId = securityTokenService.GetActualId(groupIdToken);
     GroupUser newGroupUser = new GroupUser()
     {
         UserId = User.Identity.GetUserId(),
         GroupId = groupId,
         Admin = false
     };
     groupUserService.CreateGroupUser(newGroupUser, groupInvitationService);
     securityTokenService.DeleteSecurityToken(groupIdToken);
     SocialGoalSessionFacade.Remove(SocialGoalSessionFacade.JoinGroupOrGoal);
     return RedirectToAction("Index", "Home");
 }
예제 #2
0
        public Group CreateGroup(Group group, string userId)
        {
            groupRepository.Add(group);
            SaveGroup();

            var groupUser = new GroupUser { GroupId = group.GroupId, UserId = userId,Admin=true };
            try
            {
                groupUserrepository.Add(groupUser);
                SaveGroup();
            }
            catch
            {
                groupRepository.Delete(group);
                SaveGroup();
            }            
            return group;
        }
예제 #3
0
 public ActionResult AcceptRequest(int groupId, string userId)
 {
     var newGroupUser = new GroupUser()
     {
         Admin = false,
         UserId = userId,
         GroupId = groupId
     };
     groupUserService.CreateGroupUserFromRequest(newGroupUser, groupRequestService);
     if (groupInvitationService.IsUserInvited(groupId, userId))
         groupInvitationService.AcceptInvitation(groupId, userId);
     return RedirectToAction("ShowAllRequests", new { id = groupId });
 }
예제 #4
0
 public ActionResult JoinGroup(int id)
 {
     var newGroupUser = new GroupUser()
     {
         Admin = false,
         UserId = User.Identity.GetUserId(),
         GroupId = id
     };
     groupUserService.CreateGroupUser(newGroupUser, groupInvitationService);
     if (groupRequestService.RequestSent(User.Identity.GetUserId(), id))
         groupRequestService.DeleteGroupRequest(User.Identity.GetUserId(), id);
     return RedirectToAction("Index", new { id = id });
 }
예제 #5
0
        public void Create_Goal()
        {
            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);
            string[] userRoles = { goalsetterUser.RoleName };

            principal.Setup(x => x.Identity).Returns(goalsetterUser);
            GroupUser grpuser = new GroupUser()
            {
                GroupId = 1,
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"
            };
            groupUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(grpuser);


            // Act
            Mapper.CreateMap<GroupGoalFormModel, GroupGoal>();

            GroupGoalFormModel goal = new GroupGoalFormModel()
            {
                GoalName = "t",
                GroupGoalId = 1,
                StartDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(1),
                Description = "t",
                GroupId = 1,
                GroupUserId = 1,


            };
            var result = (RedirectToRouteResult)controller.CreateGoal(goal);


            Assert.AreEqual("Index", result.RouteValues["action"]);


        }
예제 #6
0
        public void Focus()
        {
            Focus mock = new Focus()
            {
                FocusName = "x",
                FocusId = 1,
                Description = "t",
                GroupId = 1
            };
            focusRepository.Setup(x => x.GetById(1)).Returns(mock);

            GroupUser grpUser = new GroupUser()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                Admin = true
            };
            groupUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(grpUser);

            IEnumerable<GroupGoal> fakegoal = new List<GroupGoal> {
            new GroupGoal{ GroupId = 1, Description="Test1Desc",GroupGoalId =1,FocusId =1,GroupUser = grpUser},
             new GroupGoal{ GroupId = 1, Description="Test1Desc",GroupGoalId =2,FocusId = 2,GroupUser = grpUser},
          
          
          }.AsEnumerable();
            groupGoalRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupGoal, bool>>>())).Returns(fakegoal);

            Mapper.CreateMap<Focus, FocusViewModel>();
            Mapper.CreateMap<GroupGoal, GroupGoalViewModel>();


            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);


            IEnumerable<ApplicationUser> fakeUser = new List<ApplicationUser> {            
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user1",LastName="user1",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user2",LastName="user2",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user3",LastName="user3",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user4",LastName="user4",RoleId=0}
          }.AsEnumerable();
            userRepository.Setup(x => x.GetAll()).Returns(fakeUser);

            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("abc");
            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);

            ViewResult result = controller.Focus(1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual("Focus", result.ViewName);


        }
예제 #7
0
        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);
        }
예제 #8
0
        public void Supporters_Of_Updates_List()
        {

            IEnumerable<ApplicationUser> fakeUser = new List<ApplicationUser> {            
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user1",LastName="user1",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user2",LastName="user2",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user3",LastName="user3",RoleId=0},
              new ApplicationUser{Activated=true,Email="*****@*****.**",FirstName="user4",LastName="user4",RoleId=0}
          }.AsEnumerable();
            userRepository.Setup(x => x.GetAll()).Returns(fakeUser);
            IEnumerable<GroupUpdateSupport> fake = new List<GroupUpdateSupport> {            
            new GroupUpdateSupport { GroupUpdateSupportId =1, GroupUpdateId = 1, GroupUserId = 1},
            new GroupUpdateSupport { GroupUpdateSupportId =2, GroupUpdateId = 1, GroupUserId = 2},
            new GroupUpdateSupport { GroupUpdateSupportId =3, GroupUpdateId = 1, GroupUserId = 3},
          
          }.AsEnumerable();
            groupUpdateSupportRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupUpdateSupport, bool>>>())).Returns(fake);

            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);

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            PartialViewResult result = controller.SupportersOfUpdate(1) as PartialViewResult;
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(GroupUpdateSupportersViewModel), result.ViewData.Model, "Wrong View Model");
        }
예제 #9
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");
        }
예제 #10
0
        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"]);

        }
예제 #11
0
        public void Delete_Member()
        {
            GroupUser user = new GroupUser()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                GroupUserId = 1,
                GroupId = 1
            };
            groupUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(user);

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            var result = controller.DeleteMember("402bd590-fdc7-49ad-9728-40efbfe512ec", 1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
예제 #12
0
        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");
        }
예제 #13
0
 public void CreateGroupUserFromRequest(GroupUser groupUser, IGroupRequestService groupRequestService)
 {
     var oldUser = groupUserRepository.GetMany(g => g.UserId == groupUser.UserId && g.GroupId == groupUser.GroupId);
     if (oldUser.Count() == 0)
     {
         groupUserRepository.Add(groupUser);
         SaveGroupUser();
     }
     groupRequestService.ApproveRequest(groupUser.GroupId, groupUser.UserId);
 }
예제 #14
0
 public void CreateGroupUser(GroupUser groupUser, IGroupInvitationService groupInvitationService)
 {
     var oldUser = groupUserRepository.GetMany(g => g.UserId == groupUser.UserId && g.GroupId == groupUser.GroupId);
     if (oldUser.Count() == 0)
     {
         groupUserRepository.Add(groupUser);
         SaveGroupUser();
     }
     groupInvitationService.AcceptInvitation(groupUser.GroupId, groupUser.UserId);
 }