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); }
public void Invite_Email_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()); userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<ApplicationUser, bool>>>())).Returns(applicationUser); 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); var mailMessage = new MvcMailMessage(); Guid goalIdToken = Guid.NewGuid(); string email = "*****@*****.**"; // userMailerMock.Setup(mailer => mailer.PopulateBody(It.IsAny<MvcMailMessage>(), "SupportGoal", null)); mailerBase.Setup(x => x.PopulateBody(It.IsAny<MailMessage>(), "SupportGoal", null)); userMailer.Setup(x => x.Support(email, goalIdToken)).Returns(mailMessage); InviteEmailFormModel inviteEmail = new InviteEmailFormModel(); inviteEmail.Email = "*****@*****.**"; inviteEmail.GrouporGoalId = 1; // string result = controller.InviteEmail(inviteEmail) as string; //Assert.AreEqual("") }
public void DisplayComments() { IEnumerable<Comment> cmnt = new List<Comment> { new Comment { CommentId =1, UpdateId = 1,CommentText="x"}, new Comment { CommentId =2, UpdateId = 1,CommentText="y"}, new Comment { CommentId =3, UpdateId = 1,CommentText="z"}, }.AsEnumerable(); commentRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Comment, bool>>>())).Returns(cmnt); CommentUser cmtuser = new CommentUser() { CommentId = 1, UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", CommentUserId = 1 }; commentUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<CommentUser, bool>>>())).Returns(cmtuser); ApplicationUser applicationUser = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0 }; userRepository.Setup(x => x.GetById("402bd590-fdc7-49ad-9728-40efbfe512ec")).Returns(applicationUser); GoalController controller = new GoalController(goalService, metricService, focusService, supportService, updateService, commentService, userService, securityTokenService, supportInvitationService, goalStatusService, commentUserService, updateSupportService); Mapper.CreateMap<Comment, CommentsViewModel>(); PartialViewResult rslt = controller.DisplayComments(1) as PartialViewResult; Assert.IsNotNull(rslt, "View Result is null"); Assert.IsInstanceOf(typeof(IEnumerable<CommentsViewModel>), rslt.ViewData.Model, "Wrong View Model"); var cmntsView = rslt.ViewData.Model as IEnumerable<CommentsViewModel>; Assert.AreEqual(3, cmntsView.Count(), "Got wrong number of Comments"); }
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"); }
public void UpdateUser(ApplicationUser user) { userRepository.Update(user); SaveUser(); }
public void DisplayComments() { IEnumerable<GroupComment> cmnt = new List<GroupComment> { new GroupComment { GroupCommentId =1, GroupUpdateId = 1,CommentText="x"}, new GroupComment { GroupCommentId =2, GroupUpdateId = 1,CommentText="y"}, new GroupComment { GroupCommentId =3, GroupUpdateId = 1,CommentText="z"}, }.AsEnumerable(); groupCommentRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupComment, bool>>>())).Returns(cmnt); GroupCommentUser gcuser = new GroupCommentUser() { GroupCommentId = 1, GroupCommentUserId = 1, UserId = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; groupCommentUserRepository.Setup(x => x.Get(It.IsAny<Expression<Func<GroupCommentUser, bool>>>())).Returns(gcuser); ApplicationUser user = new ApplicationUser() { Id = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; userRepository.Setup(x => x.Get(It.IsAny<Expression<Func<ApplicationUser, bool>>>())).Returns(user); GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService); Mapper.CreateMap<GroupComment, GroupCommentsViewModel>(); PartialViewResult rslt = controller.DisplayComments(1) as PartialViewResult; Assert.IsNotNull(rslt, "View Result is null"); Assert.IsInstanceOf(typeof(IEnumerable<GroupCommentsViewModel>), rslt.ViewData.Model, "Wrong View Model"); var cmntsView = rslt.ViewData.Model as IEnumerable<GroupCommentsViewModel>; Assert.AreEqual(3, cmntsView.Count(), "Got wrong number of Comments"); }
public void Create_Goal() { 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()); 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"]); }
public void Add_GroupUser() { Guid guidToken = Guid.NewGuid(); SecurityToken token = new SecurityToken() { SecurityTokenId = 1, Token = guidToken, ActualID = 1 }; securityTokenRepository.Setup(x => x.Get(It.IsAny<Expression<Func<SecurityToken, bool>>>())).Returns(token); MemoryUser user = new MemoryUser("adarsh"); ApplicationUser applicationUser = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0, Id = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; 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()); EmailRequestController controller = new EmailRequestController(securityTokenService, groupUserService, supportService, groupInvitationService); 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); var httprequest = new HttpRequest("", "http://yoursite/", ""); var stringWriter = new StringWriter(); var httpResponce = new HttpResponse(stringWriter); var httpContext = new HttpContext(httprequest, httpResponce); var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 10, true, HttpCookieMode.AutoDetect, SessionStateMode.InProc, false); httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor( BindingFlags.NonPublic | BindingFlags.Instance, null, CallingConventions.Standard, new[] { typeof(HttpSessionStateContainer) }, null) .Invoke(new object[] { sessionContainer }); HttpContext.Current = httpContext; //HttpContext.Current.Request.Session["somevalue"]; controller.TempData = tempData.Object; controller.TempData["grToken"] = guidToken; var result = controller.AddGroupUser() as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }
public void Create_Focus() { 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()); 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); FocusFormModel focus = new FocusFormModel(); focus.GroupId = 1; focus.FocusName = "t"; focus.Description = "t"; Focus mock = new Focus() { FocusName = "x", FocusId = 2, Description = "t", GroupId = 1 }; //Create Mapping Mapper.CreateMap<FocusFormModel, Focus>(); // Act var result = (RedirectToRouteResult)controller.CreateFocus(focus); Assert.AreEqual("Focus", result.RouteValues["action"]); }
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 = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0, Id = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; 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); }
public void Group_Description_Required() { //Arrange 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()); 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); }
public void Search_Goal_For_Assigning() { 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()); //userRepository.Setup(x => x.GetById(1)).Returns(user); 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"); //identity.Setup(x=>x.) 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); IEnumerable<GroupUser> fakeGroupUser = new List<GroupUser> { new GroupUser {AddedDate=DateTime.Now,Admin=true,GroupId=1,GroupUserId=1,UserId="402bd590-fdc7-49ad-9728-40efbfe512ec"}, new GroupUser {AddedDate=DateTime.Now,Admin=false,GroupId=1,GroupUserId=2,UserId="402bd590-fdc7-49ad-9728-40efbfe512ed"}, new GroupUser {AddedDate=DateTime.Now,Admin=false,GroupId=1,GroupUserId=3,UserId="402bd590-fdc7-49ad-9728-40efbfe512ee"}, new GroupUser {AddedDate=DateTime.Now,Admin=true,GroupId=1,GroupUserId=4,UserId="402bd590-fdc7-49ad-9728-40efbfe512ef"}, new GroupUser {AddedDate=DateTime.Now,Admin=true,GroupId=1,GroupUserId=5,UserId="402bd590-fdc7-49ad-9728-40efbfe512eg"}, new GroupUser {AddedDate=DateTime.Now,Admin=true,GroupId=2,GroupUserId=6,UserId="402bd590-fdc7-49ad-9728-40efbfe512eh"} }.AsEnumerable(); groupUserRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<GroupUser, bool>>>())).Returns(fakeGroupUser); 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); PartialViewResult result = controller.SearchMemberForGoalAssigning(1) as PartialViewResult; Assert.IsNotNull(result); Assert.AreEqual("_MembersToSearch", result.ViewName); Assert.IsInstanceOf(typeof(IEnumerable<MemberViewModel>), result.ViewData.Model, "Wrong View Model"); }
public void Invite_User() { MemoryUser user = new MemoryUser("adarsh"); ApplicationUser applicationUser = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0, Id = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; 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); var userId = "402bd590-fdc7-49ad-9728-40efbfe512ec"; var id = 1; PartialViewResult rslt = controller.InviteUser(id, userId) as PartialViewResult; Assert.IsNotNull(rslt); Assert.IsInstanceOf(typeof(ApplicationUser), rslt.ViewData.Model, "Wrong View Model"); var userView = rslt.ViewData.Model as ApplicationUser; Assert.AreEqual("*****@*****.**", userView.Email); }
public void MyGoals_test() { 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); IEnumerable<Goal> fake = new List<Goal> { new Goal { GoalId=1,GoalName="Test1",UserId ="402bd590-fdc7-49ad-9728-40efbfe512ec",}, new Goal { GoalId=2,GoalName="Test2",UserId ="402bd590-fdc7-49ad-9728-40efbfe512ec",}, new Goal { GoalId=3,GoalName="Test3",UserId ="402bd590-fdc7-49ad-9728-40efbfe512ec",}, new Goal { GoalId=4,GoalName="Test4",UserId ="402bd590-fdc7-49ad-9728-40efbfe512ec",} }.AsEnumerable(); goalRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<Goal, bool>>>())).Returns(fake); PartialViewResult result = controller.MyGoals() as PartialViewResult; Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(IEnumerable<Goal>), result.ViewData.Model, "Wrong View Model"); }
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 Index_If_AjaxRequest_IsNull() { MemoryUser user = new MemoryUser("adarsh"); ApplicationUser applicationUser = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0, Id = "402bd590-fdc7-49ad-9728-40efbfe512ec" }; 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); NotificationController controller = new NotificationController(goalService, updateService, commentService, groupInvitationService, supportInvitationService, followRequestService, userService); 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); IEnumerable<GroupInvitation> groupInvitation = new List<GroupInvitation> { new GroupInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"}, new GroupInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed",}, new GroupInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ee"}, }.AsEnumerable(); groupInvitationRepository.Setup(x => x.GetAll()).Returns(groupInvitation); IEnumerable<SupportInvitation> supportInvitation = new List<SupportInvitation> { new SupportInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed",FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"}, new SupportInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId ="402bd590-fdc7-49ad-9728-40efbfe512ed"}, new SupportInvitation{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId ="402bd590-fdc7-49ad-9728-40efbfe512ee"}, }.AsEnumerable(); supportInvitationRepository.Setup(x => x.GetAll()).Returns(supportInvitation); IEnumerable<FollowRequest> followInvitation = new List<FollowRequest> { new FollowRequest{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed",FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec"}, new FollowRequest{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId ="402bd590-fdc7-49ad-9728-40efbfe512ed"}, new FollowRequest{ Accepted=false,ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec",FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ee"}, }.AsEnumerable(); followRequestRepository.Setup(x => x.GetMany(It.IsAny<Expression<Func<FollowRequest, bool>>>())).Returns(followInvitation); Mapper.CreateMap<GroupInvitation, NotificationViewModel>(); Mapper.CreateMap<SupportInvitation, NotificationViewModel>(); Mapper.CreateMap<FollowRequest, NotificationViewModel>(); ViewResult result = controller.Index(1) as ViewResult; Assert.IsNotNull(result); }
public void SearchGoalSearch_User_Which_Support_The_Goal() { 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); 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); var searchString = "e"; JsonResult result = controller.SearchUser(searchString, 1); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(JsonResult), result); }
private bool ValidatePassword(ApplicationUser user, string password) { var encoded = Md5Encrypt.Md5EncryptPassword(password); return user.PasswordHash.Equals(encoded); }
public void Create_Support_Test() { 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); //Act var rslt = controller.SupportGoalNow(1) as RedirectToRouteResult; Assert.AreEqual("Index", rslt.RouteValues["action"]); }
public ApplicationUser getApplicationUser() { ApplicationUser applicationUser = new ApplicationUser() { Activated = true, Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", UserName = "******", RoleId = 0, Id = "402bd590-fdc7-49ad-9728-40efbfe512ec", DateCreated = DateTime.Now, LastLoginTime = DateTime.Now, ProfilePicUrl = null, }; return applicationUser; }
public void Display_Updates() { MemoryUser user = new MemoryUser("adarsh"); ApplicationUser applicationUser = new ApplicationUser() { Email = "*****@*****.**", FirstName = "Adarsh", LastName = "Vikraman", RoleId = 0, Id="402bd590-fdc7-49ad-9728-40efbfe512ec" }; 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"); //identity.Setup(x=>x.) 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); Metric fakeMetric = new Metric() { MetricId = 1, Type = "%" }; GroupGoal goal = new GroupGoal() { Metric = fakeMetric, Target = 100 }; 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=2 }, 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); Mapper.CreateMap<GroupUpdate, GroupUpdateViewModel>(); // GroupController controller = new GroupController(groupService, groupUserService, userService, metricService, focusService, groupgoalService, groupInvitationService, securityTokenService, groupUpdateService, groupCommentService, goalStatusService, groupRequestService, followUserService, groupCommentUserService, groupUpdateSupportService, groupUpdateUserService); PartialViewResult rslt = controller.DisplayUpdates(1) as PartialViewResult; Assert.IsNotNull(rslt); Assert.IsInstanceOf(typeof(GroupUpdateListViewModel), rslt.ViewData.Model, "Wrong View Model"); }