Пример #1
0
 public IEnumerable<ValidationResult> CanAddGroup(Group newGroup)
 {
     Group group;
     if (newGroup.GroupId == 0)
         group = groupRepository.Get(g => g.GroupName == newGroup.GroupName);
     else
         group = groupRepository.Get(g => g.GroupName == newGroup.GroupName && g.GroupId != newGroup.GroupId);
     if (group != null)
     {
         yield return new ValidationResult("GroupName", Resources.GroupExists);
     }
 }
Пример #2
0
 public void UpdateGroup(Group group)
 {
     groupRepository.Update(group);
     SaveGroup();
 }
Пример #3
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;
        }
Пример #4
0
        public void Delete_Group_Post()
        {
            Group fake = new Group()
            {
                GroupId = 1,
                GroupName = "test",
                Description = "test"
            };
            groupRepository.Setup(x => x.GetById(fake.GroupId)).Returns(fake);


            Assert.IsNotNull(fake);
            Assert.AreEqual(1, fake.GroupId);
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            var result = controller.DeleteConfirmedGroup(1) as RedirectToRouteResult;
            Assert.AreEqual("Index", result.RouteValues["action"]);

        }
Пример #5
0
        public void Edit_Group_Get_ReturnsView()
        {


            Group group = new Group() { GroupId = 1, GroupName = "Test", Description = "test" };
            groupRepository.Setup(x => x.GetById(1)).Returns(group);
            Mapper.CreateMap<Group, GroupFormModel>();
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);


            ViewResult actual = controller.EditGroup(1) as ViewResult;


            Assert.IsNotNull(actual, "View Result is null");
            Assert.IsInstanceOf(typeof(GroupFormModel),
                actual.ViewData.Model, "Wrong View Model");
        }
Пример #6
0
        public void Delete_Group_Get_ReturnsView()
        {
            Group fake = new Group()
            {
                GroupId = 1,
                GroupName = "test",
                Description = "test"
            };
            groupRepository.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.DeleteGroup(1) as ViewResult;
            Assert.IsNotNull(result, "View Result is null");
            Assert.IsInstanceOf(typeof(Group),
                 result.ViewData.Model, "Wrong View Model");
            var group = result.ViewData.Model as Group;
            Assert.AreEqual("test", group.Description, "Got wrong Focus Description");

        }
Пример #7
0
        public void Create_Focus_Get_ReturnsView()
        {
            //Arrange

            Group group = new Group() { GroupId = 1, GroupName = "Test", Description = "test" };
            groupRepository.Setup(x => x.GetById(1)).Returns(group);
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            //Act
            ActionResult result = controller.CreateFocus(1) as ActionResult;
            //Assert
            Assert.IsNotNull(result);

        }
Пример #8
0
        public void Invite_Users()
        {
            Mapper.CreateMap<Group, GroupViewModel>();
            Group grp = new Group()
            {
                GroupId = 1,
                GroupName = "t",
                Description = "t"
            };
            groupRepository.Setup(x => x.GetById(1)).Returns(grp);

            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            ViewResult reslt = controller.InviteUsers(1) as ViewResult;
            Assert.IsNotNull(reslt);
            Assert.IsInstanceOf(typeof(GroupViewModel),
               reslt.ViewData.Model, "Wrong View Model");
            //var grpview = reslt.ViewData.Model as GroupViewModel;
            //Assert.AreEqual("t", grpview.GroupName);

        }
Пример #9
0
        public void SearchUserForGroup()
        {

            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.GetMany(It.IsAny<Expression<Func<ApplicationUser, bool>>>())).Returns(fakeUser);

            Group grp = new Group()
            {
                GroupId = 1
            };
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            var searchString = "e";
            JsonResult result = controller.SearchUserForGroup(searchString, 1);
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(JsonResult), result);



        }
Пример #10
0
        public void Index()
        {

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


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

            Group group = new Group() { GroupId = 1, GroupName = "Test", Description = "test" };
            groupRepository.Setup(x => x.GetById(1)).Returns(group);

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

            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 = 2}
          }.AsEnumerable();
            focusRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Focus, bool>>>())).Returns(fakeFocus);

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



            Mapper.CreateMap<Group, GroupViewModel>();
            Mapper.CreateMap<GroupGoal, GroupGoalViewModel>();

            ViewResult result = controller.Index(1) as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.ViewName);
            Assert.IsInstanceOfType(typeof(GroupViewModel),
                result.ViewData.Model, "WrongType");
        }
Пример #11
0
        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"]);

        }