public async Task VerifyCodePostRedirectsToHomeControllerIndexWhenTwoFactorSignInAsyncSucceedsAndReturnUrlIsNotLocalUrl() { var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())) .ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success); var urlHelper = new Mock<IUrlHelper>(); urlHelper.Setup(x => x.IsLocalUrl(It.IsAny<string>())).Returns(false); var sut = new AdminController(null, signInManager.Object, null, null, null) { Url = urlHelper.Object }; var result = await sut.VerifyCode(new VerifyCodeViewModel()) as RedirectToActionResult; Assert.Equal(result.ActionName, nameof(HomeController.Index)); Assert.Equal(result.ControllerName, "Home"); }
public async Task VerifyCodePostReturnsLockoutViewIfTwoFactorSignInAsyncFailsAndIsLockedOut() { var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.LockedOut); var sut = new AdminController(null, signInManager.Object, null, null, null); var result = await sut.VerifyCode(new VerifyCodeViewModel()) as ViewResult; Assert.Equal(result.ViewName, "Lockout"); }
public async Task VerifyCodePostRedirectsToReturnUrlWhenTwoFactorSignInAsyncSucceedsAndReturnUrlIsLocalUrl() { var model = new VerifyCodeViewModel { ReturnUrl = "returnUrl" }; var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(Microsoft.AspNetCore.Identity.SignInResult.Success); var urlHelper = new Mock<IUrlHelper>(); urlHelper.Setup(x => x.IsLocalUrl(model.ReturnUrl)).Returns(true); var sut = new AdminController(null, signInManager.Object, null, null, null) { Url = urlHelper.Object }; var result = await sut.VerifyCode(model) as RedirectResult; Assert.Equal(result.Url, model.ReturnUrl); }
public async Task VerifyCodePostAddsErrorMessageToModelStateErrorWhenTwoFactorSignInAsyncIsNotSuccessful() { var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(new Microsoft.AspNetCore.Identity.SignInResult()); var sut = new AdminController(null, signInManager.Object, null, null, null); await sut.VerifyCode(new VerifyCodeViewModel()); var errorMessage = sut.ModelState.GetErrorMessages().Single(); Assert.Equal(errorMessage, "Invalid code."); }
public async Task VerifyCodePostInvokesTwoFactorSignInAsyncWithCorrectParameters() { var model = new VerifyCodeViewModel { Provider = "provider", Code = "code", RememberBrowser = true, RememberMe = true }; var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.TwoFactorSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())).ReturnsAsync(new Microsoft.AspNetCore.Identity.SignInResult()); var sut = new AdminController(null, signInManager.Object, null, null, null); await sut.VerifyCode(model); signInManager.Verify(x => x.TwoFactorSignInAsync(model.Provider, model.Code, model.RememberMe, model.RememberBrowser)); }
public async Task VerifyCodeGetReturnsCorrectViewModel() { const string provider = "provider"; const bool rememberMe = true; const string returnUrl = "returnUrl"; var signInManager = CreateSignInManagerMock(); signInManager.Setup(x => x.GetTwoFactorAuthenticationUserAsync()).ReturnsAsync(new ApplicationUser()); var sut = new AdminController(null, signInManager.Object, null, null, null); var result = await sut.VerifyCode(provider, rememberMe, returnUrl) as ViewResult; var modelResult = result.ViewData.Model as VerifyCodeViewModel; Assert.Equal(modelResult.Provider, provider); Assert.Equal(modelResult.ReturnUrl, returnUrl); Assert.Equal(modelResult.RememberMe, rememberMe); }
public async Task VerifyCodeGetReturnsErrorViewWhenUserIsNull() { var signInManager = CreateSignInManagerMock(); var sut = new AdminController(null, signInManager.Object, null, null, null); var result = await sut.VerifyCode(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>()) as ViewResult; Assert.Equal(result.ViewName, "Error"); }
public async Task VerifyCodeGetInvokesGetTwoFactorAuthenticationUserAsync() { var signInManager = CreateSignInManagerMock(); var sut = new AdminController(null, signInManager.Object, null, null, null); await sut.VerifyCode(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<string>()); signInManager.Verify(x => x.GetTwoFactorAuthenticationUserAsync(), Times.Once); }