예제 #1
0
        public async Task ResetPasswordPostRedirectsToCorrectAction_WhenUsersPasswordResetSucceeded_AndUserIsNotNull_AndModelStateIsValid()
        {
            const string email = "*****@*****.**";
            var vm = new ResetPasswordViewModel { Email = email };
            var userManager = CreateUserManagerMock();

            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ResetPasswordAsync(user, It.IsAny<string>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));
            var sut = new AccountController(userManager.Object, null, null, null, null);

            var result = await sut.ResetPassword(vm) as RedirectToActionResult;

            Assert.Equal("ResetPasswordConfirmation", result.ActionName);
        }
예제 #2
0
        public async Task ResetPasswordPostInvokesResetPasswordAsyncWithCorrectParameters_WhenUserIsNotNull_AndModelStateIsValid()
        {
            const string email = "*****@*****.**";
            var vm = new ResetPasswordViewModel
            {
                Email = email,
                Password = "******",
                Code = "code"
            };

            var userManager = CreateUserManagerMock();
            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ResetPasswordAsync(user, It.IsAny<string>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            await sut.ResetPassword(vm);

            userManager.Verify(m => m.ResetPasswordAsync(user, It.Is<string>(y => y == vm.Code), It.Is<string>(y => y == vm.Password)), Times.Once);
        }
예제 #3
0
        public async Task ResetPasswordPostInvokesFindByNameAsyncWithTheCorrecEmail_WhenModelStateIsValid()
        {
            const string email = "*****@*****.**";

            var vm = new ResetPasswordViewModel { Email = email };

            var userManager = CreateUserManagerMock();
            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ResetPasswordAsync(user, It.IsAny<string>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Success));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            await sut.ResetPassword(vm);

            userManager.Verify(m => m.FindByNameAsync(email), Times.Once);
        }
예제 #4
0
        public async Task ResetPasswordPostReturnsAView_WhenUsersPasswordResetFailed_AndUserIsNotNull_AndModelStateIsValid()
        {
            const string email = "*****@*****.**";
            var vm = new ResetPasswordViewModel { Email = email };
            var userManager = CreateUserManagerMock();
            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ResetPasswordAsync(user, It.IsAny<string>(), It.IsAny<string>())).Returns(() => Task.FromResult(IdentityResult.Failed()));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            var result = await sut.ResetPassword(vm) as ViewResult;

            Assert.IsType<ViewResult>(result);
            Assert.Null(result.ViewData.Model);
        }
예제 #5
0
        public async Task ResetPasswordPostAddsIdentityResultErrorsToModelStateErrors_WhenUsersPasswordResetFailed_AndUserIsNotNull_AndModelStateIsValid()
        {
            const string email = "*****@*****.**";

            var vm = new ResetPasswordViewModel { Email = email };
            var userManager = CreateUserManagerMock();
            var identityResult = IdentityResult.Failed(new IdentityError { Description = "IdentityErrorDescription" });
            var user = new ApplicationUser();
            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult(user));
            userManager.Setup(x => x.ResetPasswordAsync(user, It.IsAny<string>(), It.IsAny<string>())).Returns(() => Task.FromResult(identityResult));

            var sut = new AccountController(userManager.Object, null, null, null, null);
            await sut.ResetPassword(vm);

            var errorMessages = sut.ModelState.GetErrorMessages();
            Assert.Equal(identityResult.Errors.Select(x => x.Description).Single(), errorMessages.Single());
        }
예제 #6
0
        public async Task ResetPasswordPostRedirectsToCorrectActionWhenUserIsNullAndModelStateIsValid()
        {
            var email = "*****@*****.**";

            var vm = new ResetPasswordViewModel()
            {
                Email = email
            };

            var userManager = CreateUserManagerMock();

            userManager.Setup(x => x.FindByNameAsync(email)).Returns(() => Task.FromResult((ApplicationUser)null));
            var sut = new AccountController(userManager.Object, null, null, null, null);

            var result = await sut.ResetPassword(vm) as RedirectToActionResult;

            Assert.Equal("ResetPasswordConfirmation", result.ActionName);
        }