Пример #1
0
 public ActionResult CreateGroup(GroupFormModel newGroup)
 {
     var userId = User.Identity.GetUserId();
     Group group = Mapper.Map<GroupFormModel, Group>(newGroup);
     var errors = groupService.CanAddGroup(group).ToList();
     ModelState.AddModelErrors(errors);
     if (ModelState.IsValid)
     {
         //group.UserId = ((SocialGoalUser)(User.Identity)).UserId;
         var createdGroup = groupService.CreateGroup(group, userId);
         //var createdGroup = groupService.GetGroup(newGroup.GroupName);
         //var groupAdmin = new GroupUser { GroupId = createdGroup.GroupId, UserId = ((SocialGoalUser)(User.Identity)).UserId, Admin = true };
         //groupUserService.CreateGroupUser(groupAdmin, groupInvitationService);
         return RedirectToAction("Index", new { id = createdGroup.GroupId });
     }
     return View("CreateGroup", newGroup);
 }
Пример #2
0
 public ActionResult EditGroup(GroupFormModel groupFormViewModel)
 {
     Group group = Mapper.Map<GroupFormModel, Group>(groupFormViewModel);
     var errors = groupService.CanAddGroup(group).ToList();
     ModelState.AddModelErrors(errors);
     if (ModelState.IsValid)
     {
         groupService.UpdateGroup(group);
         return RedirectToAction("Index", new { id = group.GroupId });
     }
     return View("_EditGroup", groupFormViewModel);
 }
Пример #3
0
 //
 // GET: /Group/Create
 public PartialViewResult CreateGroup()
 {
     var groupFormViewModel = new GroupFormModel();
     return PartialView(groupFormViewModel);
 }
Пример #4
0
        public void Create_Group()
        {

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




            // Act
            Mapper.CreateMap<GroupFormModel, Group>();
            GroupFormModel group = new GroupFormModel()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                CreatedDate = DateTime.Now,
                Description = "Mock",
                GroupName = "Mock",
                GroupId = 1,

            };
            var result = (RedirectToRouteResult)controller.CreateGroup(group);

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



        }
Пример #5
0
        public void Group_Description_Required()
        {
            //Arrange

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


            principal.Setup(x => x.Identity).Returns(goalsetterUser);


            // The MVC pipeline doesn't run, so binding and validation don't run. 
            controller.ModelState.AddModelError("", "mock error message");


            // Act          

            Mapper.CreateMap<GroupFormModel, Group>();
            GroupFormModel group = new GroupFormModel();
            group.Description = string.Empty;
            var result = (ViewResult)controller.CreateGroup(group);
            // Assert - check that we are passing an invalid model to the view
            Assert.AreEqual(false, result.ViewData.ModelState.IsValid);
            Assert.AreEqual("CreateGroup", result.ViewName);

        }
Пример #6
0
        public void Create_Group_Get_ReturnsView()
        {
            //Arrange
            GroupFormModel group = new GroupFormModel();
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);
            //Act
            PartialViewResult result = controller.CreateGroup() as PartialViewResult;
            //Assert
            Assert.IsNotNull(result);

        }
Пример #7
0
        public void Edit_Group_Post()
        {
            GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService);

            // Act
            Mapper.CreateMap<GroupFormModel, Group>();
            GroupFormModel group = new GroupFormModel()
            {
                UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",
                CreatedDate = DateTime.Now,
                Description = "Mock",
                GroupName = "Mock",
                GroupId = 1

            };
            var result = (RedirectToRouteResult)controller.EditGroup(group);
            Assert.AreEqual("Index", result.RouteValues["action"]);

        }