public void DoesntSendAccountChangedEmailsIfConfirmationTokenDoesntMatch() { var user = new User { EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "the-token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername("username")) .Returns(user); controller.MockUserService .Setup(u => u.ConfirmEmailAddress(user, "faketoken")) .Returns(false); // act: var model = (controller.Confirm("username", "faketoken") as ViewResult).Model as EmailConfirmationModel; // verify: Assert.False(model.SuccessfulConfirmation); Assert.False(model.ConfirmingNewAccount); controller.MockMessageService .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny <MailAddress>(), It.IsAny <string>()), Times.Never()); controller.MockMessageService .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(It.IsAny <User>(), It.IsAny <string>()), Times.Never()); }
public void Returns404WhenTokenIsEmpty() { var controller = new TestableUsersController(); var result = controller.Confirm("username", "") as HttpNotFoundResult; Assert.NotNull(result); }
public void ReturnsConfirmedWhenTokenMatchesUser() { var user = new User { UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "the-token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername("username")) .Returns(user); controller.MockUserService .Setup(u => u.ConfirmEmailAddress(user, "the-token")) .Returns(true); var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel; Assert.True(model.SuccessfulConfirmation); }
public void ReturnsFalseWhenTokenDoesNotMatchUser() { var user = new User { EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "the-token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername("username")) .Returns(user); controller.MockUserService .Setup(u => u.ConfirmEmailAddress(user, "not-the-token")) .Returns(false); var model = (controller.Confirm("username", "not-the-token") as ViewResult).Model as EmailConfirmationModel; Assert.False(model.SuccessfulConfirmation); }
public void SendsAccountChangedNoticeWhenConfirmingChangedEmail() { var user = new User { EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "the-token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername("username")) .Returns(user); controller.MockUserService .Setup(u => u.ConfirmEmailAddress(user, "the-token")) .Returns(true); var model = (controller.Confirm("username", "the-token") as ViewResult).Model as EmailConfirmationModel; Assert.True(model.SuccessfulConfirmation); Assert.False(model.ConfirmingNewAccount); controller.MockMessageService .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(user, "*****@*****.**")); }
public void DoesntSendAccountChangedEmailsIfConfirmationTokenDoesntMatch() { var user = new User { EmailAddress = "*****@*****.**", UnconfirmedEmailAddress = "*****@*****.**", EmailConfirmationToken = "the-token" }; var controller = new TestableUsersController(); controller.MockUserService .Setup(u => u.FindByUsername("username")) .Returns(user); controller.MockUserService .Setup(u => u.ConfirmEmailAddress(user, "faketoken")) .Returns(false); // act: var model = (controller.Confirm("username", "faketoken") as ViewResult).Model as EmailConfirmationModel; // verify: Assert.False(model.SuccessfulConfirmation); Assert.False(model.ConfirmingNewAccount); controller.MockMessageService .Verify(m => m.SendEmailChangeConfirmationNotice(It.IsAny<MailAddress>(), It.IsAny<string>()), Times.Never()); controller.MockMessageService .Verify(m => m.SendEmailChangeNoticeToPreviousEmailAddress(It.IsAny<User>(), It.IsAny<string>()), Times.Never()); }