public void TestThat_Complete_SetsTheSuppliedMessageOnTheView()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (ViewResult)controller.Complete("a message");

            Assert.That(result.ViewBag.Message, Is.EqualTo("a message"));
        }
        public void TestThat_EmailConfirmation_RedirectsToTheCorrectView()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (ViewResult)controller.EmailConfirmation("token");

            Assert.That(result.ViewName, Is.EqualTo("Step3"));
        }
        public void TestThat_ResetPassword_AddsAValidationError_WhenTheModelHasAnInvalidUserNameAndEmailAddress()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var model = new ResetPasswordStepOneModel { UserName = null, EmailAddress = null };
            controller.ResetPassword(model);

            Assert.That(controller.ModelState.Count, Is.EqualTo(1));
        }
        public void TestThat_EmailConfirmation_PassesTheSuppliedToken_ToTheView()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (ViewResult)controller.EmailConfirmation("token");

            var model = (ResetPasswordStepThreeModel)result.Model;
            Assert.That(model.ResetToken, Is.EqualTo("token"));
        }
        public void TestThat_ResetPassword_GeneratesAPasswordResetTokenForTheUser_WhenAValidUserIsFound_FromAUserName()
        {
            var userProfileRepository = Substitute.For<IUserProfileRepository>();
            userProfileRepository.GetUserProfileByUserName("bob").Returns(new UserProfile { UserName = "******", EmailAddress = "*****@*****.**" });
            var resetPasswordService = Substitute.For<IResetPasswordService>();
            var controller = new ResetPasswordController(userProfileRepository, resetPasswordService, new EmailMessengerFactory(Substitute.For<IPostman>()));
            controller.SetupWithHttpContextAndUrlHelper();

            var model = new ResetPasswordStepOneModel { UserName = "******" };
            controller.ResetPassword(model);

            resetPasswordService.Received().GeneratePasswordResetToken("bob", Arg.Any<int>());
        }
        public void TestThat_Start_BeginsAtStepOne()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (ViewResult)controller.Start();

            Assert.That(result.ViewName, Is.EqualTo("Step1"));
        }
        public void TestThat_SaveNewPassword_RedirectsToStepThree_WhenTheModelIsInvalid()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));
            controller.ModelState.AddModelError("", "invalid");

            var result = (ViewResult)controller.SaveNewPassword(new ResetPasswordStepThreeModel());

            Assert.That(result.ViewName, Is.EqualTo("Step3"));
        }
        public void TestThat_SaveNewPassword_RedirectsToStepThree_WhenThePasswordCouldNotBeChanged()
        {
            var resetPasswordService = Substitute.For<IResetPasswordService>();
            resetPasswordService.ResetPassword(Arg.Any<string>(), Arg.Any<string>()).Returns(false);
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), resetPasswordService, new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (ViewResult)controller.SaveNewPassword(new ResetPasswordStepThreeModel());

            Assert.That(result.ViewName, Is.EqualTo("Step3"));
        }
        public void TestThat_SaveNewPassword_RedirectsToCompletions_WhenThePasswordWasBeChanged()
        {
            var resetPasswordService = Substitute.For<IResetPasswordService>();
            resetPasswordService.ResetPassword(Arg.Any<string>(), Arg.Any<string>()).Returns(true);
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), resetPasswordService, new EmailMessengerFactory(Substitute.For<IPostman>()));

            var result = (RedirectToRouteResult)controller.SaveNewPassword(new ResetPasswordStepThreeModel());

            Assert.That(result.RouteValues["action"], Is.EqualTo("Complete"));
        }
        public void TestThat_SaveNewPassword_AddsAnError_WhenThePasswordCouldNotBeChanged()
        {
            var resetPasswordService = Substitute.For<IResetPasswordService>();
            resetPasswordService.ResetPassword(Arg.Any<string>(), Arg.Any<string>()).Returns(false);
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), resetPasswordService, new EmailMessengerFactory(Substitute.For<IPostman>()));

            controller.SaveNewPassword(new ResetPasswordStepThreeModel());

            Assert.That(controller.ModelState.Count, Is.EqualTo(1));
        }
        public void TestThat_ResetPassword_SendsAnEmailToTheUser_WhenAValidUserIsFound_FromAUserName()
        {
            var userProfileRepository = Substitute.For<IUserProfileRepository>();
            var userProfile = new UserProfile { UserName = "******", EmailAddress = "*****@*****.**" };
            userProfileRepository.GetUserProfileByUserName("bob").Returns(userProfile);
            var postman = Substitute.For<IPostman>();
            var controller = new ResetPasswordController(userProfileRepository, Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(postman));
            controller.SetupWithHttpContextAndUrlHelper();

            var model = new ResetPasswordStepOneModel { UserName = "******" };
            controller.ResetPassword(model);

            var expectedMessage = MailMessage.FromTemplate(PasswordResetMailTemplate.Create(string.Empty), userProfile);
            postman.Received().Deliver(expectedMessage);
        }
        public void TestThat_ResetPassword_RedirectsToStepTwo_WhenTheModelHasAValidUserName_ButTheUserProfileCouldNotBeFound()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var model = new ResetPasswordStepOneModel { UserName = "******" };
            var result = (ViewResult)controller.ResetPassword(model);

            Assert.That(result.ViewName, Is.EqualTo("Step2"));
        }
        public void TestThat_ResetPassword_RedirectsBackToStepOne_WhenTheModelHasAnInvalidUserNameAndEmailAddress()
        {
            var controller = new ResetPasswordController(Substitute.For<IUserProfileRepository>(), Substitute.For<IResetPasswordService>(), new EmailMessengerFactory(Substitute.For<IPostman>()));

            var model = new ResetPasswordStepOneModel { UserName = null, EmailAddress = null };
            var result = (ViewResult)controller.ResetPassword(model);

            Assert.That(result.ViewName, Is.EqualTo("Step1"));
        }