public void SendsEmailChangeConfirmationNoticeWhenEmailConfirmationTokenChanges() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny <string>())) .Returns(user); controller.MockUserService .Setup(u => u.UpdateProfile(user, "*****@*****.**", true)) .Callback(() => user.EmailConfirmationToken = "token"); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal( "Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one.", controller.TempData["Message"]); }
public void DoesNotSendEmailChangeConfirmationNoticeWhenTokenDoesNotChange() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true, EmailConfirmationToken = "token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny <string>())) .Returns(user); controller.MockMessageService .Setup(m => m.SendEmailChangeConfirmationNotice(It.IsAny <MailAddress>(), It.IsAny <string>())) .Throws(new InvalidOperationException()); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal("Account settings saved!", controller.TempData["Message"]); controller.MockUserService .Verify(u => u.UpdateProfile(user, It.IsAny <string>(), true)); }
public void UpdatesEmailAllowedSetting() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny <string>())) .Returns(user); controller.MockUserService .Setup(u => u.UpdateProfile(user, "*****@*****.**", false)) .Verifiable(); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); controller.MockUserService .Verify(u => u.UpdateProfile(user, "*****@*****.**", false)); Assert.Equal("Account settings saved!", controller.TempData["Message"]); }
public void WithInvalidUsernameReturnsFileNotFound() { var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny <string>())) .ReturnsNull(); var result = controller.Edit(new EditProfileViewModel()) as HttpNotFoundResult; Assert.NotNull(result); }
public void WithInvalidUsernameReturnsFileNotFound() { var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny<string>())) .ReturnsNull(); var result = controller.Edit(new EditProfileViewModel()) as HttpNotFoundResult; Assert.NotNull(result); }
public void DoesNotSendEmailChangeConfirmationNoticeWhenTokenDoesNotChange() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true, EmailConfirmationToken = "token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny<string>())) .Returns(user); controller.MockMessageService .Setup(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>())) .Throws(new InvalidOperationException()); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal("Account settings saved!", controller.TempData["Message"]); controller.MockUserService .Verify(u => u.UpdateProfile(user, It.IsAny<string>(), true)); }
public void SendsEmailChangeConfirmationNoticeWhenEmailConfirmationTokenChanges() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny<string>())) .Returns(user); controller.MockUserService .Setup(u => u.UpdateProfile(user, "*****@*****.**", true)) .Callback(() => user.EmailConfirmationToken = "token"); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = true }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); Assert.Equal( "Account settings saved! We sent a confirmation email to verify your new email. When you confirm the email address, it will take effect and we will forget the old one.", controller.TempData["Message"]); }
public void UpdatesEmailAllowedSetting() { var user = new User { EmailAddress = "*****@*****.**", EmailAllowed = true }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername(It.IsAny<string>())) .Returns(user); controller.MockUserService .Setup(u => u.UpdateProfile(user, "*****@*****.**", false)) .Verifiable(); var model = new EditProfileViewModel { EmailAddress = "*****@*****.**", EmailAllowed = false }; var result = controller.Edit(model) as RedirectToRouteResult; Assert.NotNull(result); controller.MockUserService .Verify(u => u.UpdateProfile(user, "*****@*****.**", false)); Assert.Equal("Account settings saved!", controller.TempData["Message"]); }