public string InviteEmail(InviteEmailFormModel inviteUser) { var user = userService.GetUsersByEmail(inviteUser.Email); if (user != null) { if (!groupUserService.CanInviteUser(user.Id, inviteUser.GrouporGoalId)) return Resources.PersonJoined; } if (ModelState.IsValid) { Guid groupIdToken = Guid.NewGuid(); SecurityToken groupIdSecurity = new SecurityToken() { Token = groupIdToken, ActualID = inviteUser.GrouporGoalId }; securityTokenService.CreateSecurityToken(groupIdSecurity); UserMailer.Invite(inviteUser.Email, groupIdToken).Send(); return Resources.InvitationSent; } else return Resources.WrongEmail; }
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("") }