public void TestIngresoExitosoLogin() { //Arrange var userStore = new Mock<IUserStore<ApplicationUser>>(); var userManager = new Mock<ApplicationUserManager>(userStore.Object); var authenticationManager = new Mock<IAuthenticationManager>(); var signInManager = new Mock<ApplicationSignInManager>(userManager.Object, authenticationManager.Object); signInManager.Setup(s => s.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())) .Returns<string, string, bool, bool>(MockPasswordSignInAsync); var controller = new AccountController(userManager.Object, signInManager.Object); var contextMock = new Mock<HttpContextBase>(); controller.Url = new UrlHelper(new RequestContext(contextMock.Object, new RouteData())); var loginViewmodel = new LoginViewModel { Email = "*****@*****.**", Password = "******", RememberMe = false }; var returnUrl = "/Home/Index"; //Act var result = controller.Login(loginViewmodel, returnUrl); //Assert Assert.IsInstanceOfType(result.Result, typeof(RedirectResult)); Assert.AreEqual(returnUrl, (result.Result as RedirectResult).Url); }
public void TestLoginIngresoFallido() { var userStore = new Mock<IUserStore<ApplicationUser>>(); var userManager = new Mock<ApplicationUserManager>(userStore.Object); var authenticationManager = new Mock<IAuthenticationManager>(); var signInManager = new Mock<ApplicationSignInManager>(userManager.Object, authenticationManager.Object); signInManager.Setup(s => s.PasswordSignInAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>())) .Returns<string, string, bool, bool>(MockPasswordSignInAsync); var controller = new AccountController(userManager.Object, signInManager.Object); var contextMock = new Mock<HttpContextBase>(); controller.Url = new UrlHelper(new RequestContext(contextMock.Object, new RouteData())); var loginViewmodel = new LoginViewModel { Email = "*****@*****.**", Password = "******", RememberMe = false }; var returnUrl = "/Home/Index"; //Act var result = controller.Login(loginViewmodel, returnUrl); //Assert Assert.IsInstanceOfType(result.Result, typeof(ViewResult)); Assert.AreEqual("Usuario o Clave incorrectos", (result.Result as ViewResult).ViewData.ModelState[""].Errors[0].ErrorMessage); }