public void TestThat_ResetPassword_RedirectsBackToStepOne_WhenTheModelHasAnInvalidUserNameAndEmailAddress() { var controller = new ResetPasswordController(Substitute.For <IUserProfileRepository>(), Substitute.For <IResetPasswordThingy>(), Substitute.For <IResetPasswordEmailSender>()); var model = new ResetPasswordStepOneModel { UserName = null, EmailAddress = null }; var result = (ViewResult)controller.ResetPassword(model); Assert.That(result.ViewName, Is.EqualTo("Step1")); }
public void TestThat_ResetPassword_RedirectsBackToStepOne_WhenTheModelIsInvalid() { var controller = new ResetPasswordController(Substitute.For <IUserProfileRepository>(), Substitute.For <IResetPasswordThingy>(), Substitute.For <IResetPasswordEmailSender>()); controller.ModelState.AddModelError("", "invalid"); var model = new ResetPasswordStepOneModel(); var result = (ViewResult)controller.ResetPassword(model); Assert.That(result.ViewName, Is.EqualTo("Step1")); }
public void TestThat_ResetPassword_RedirectsToStepTwo_WhenTheModelHasAValidEmailAddress_ButTheUserProfileCouldNotBeFound() { var controller = new ResetPasswordController(Substitute.For <IUserProfileRepository>(), Substitute.For <IResetPasswordThingy>(), Substitute.For <IResetPasswordEmailSender>()); var model = new ResetPasswordStepOneModel { EmailAddress = "*****@*****.**" }; var result = (ViewResult)controller.ResetPassword(model); Assert.That(result.ViewName, Is.EqualTo("Step2")); }
public void TestThat_ResetPassword_AddsAValidationError_WhenTheModelHasAnInvalidUserNameAndEmailAddress() { var controller = new ResetPasswordController(Substitute.For <IUserProfileRepository>(), Substitute.For <IResetPasswordThingy>(), Substitute.For <IResetPasswordEmailSender>()); var model = new ResetPasswordStepOneModel { UserName = null, EmailAddress = null }; controller.ResetPassword(model); Assert.That(controller.ModelState.Count, Is.EqualTo(1)); }
public void TestThat_ResetPassword_SendsAnEmailToTheUser_WhenAValidUserIsFound_FromAnEmailAddress() { var userProfileRepository = Substitute.For <IUserProfileRepository>(); userProfileRepository.GetUserProfileByEmailAddress("*****@*****.**").Returns(new UserProfile { UserName = "******", EmailAddress = "*****@*****.**" }); var resetPasswordEmailSender = Substitute.For <IResetPasswordEmailSender>(); var controller = new ResetPasswordController(userProfileRepository, Substitute.For <IResetPasswordThingy>(), resetPasswordEmailSender); controller.SetupWithHttpContextAndUrlHelper(); var model = new ResetPasswordStepOneModel { EmailAddress = "*****@*****.**" }; controller.ResetPassword(model); resetPasswordEmailSender.Received().SendEmail(Arg.Any <string>(), Arg.Any <string>(), "*****@*****.**", Arg.Any <string>()); }
public void TestThat_ResetPassword_GeneratesAPasswordResetTokenForTheUser_WhenAValidUserIsFound_FromAUserName() { var userProfileRepository = Substitute.For <IUserProfileRepository>(); userProfileRepository.GetUserProfileByUserName("bob").Returns(new UserProfile { UserName = "******", EmailAddress = "*****@*****.**" }); var resetPasswordThingy = Substitute.For <IResetPasswordThingy>(); var controller = new ResetPasswordController(userProfileRepository, resetPasswordThingy, Substitute.For <IResetPasswordEmailSender>()); controller.SetupWithHttpContextAndUrlHelper(); var model = new ResetPasswordStepOneModel { UserName = "******" }; controller.ResetPassword(model); resetPasswordThingy.Received().GeneratePasswordResetToken("bob", Arg.Any <int>()); }