public void Login_Post_Success_InvalidReturnUrl() { // arrange var mockAuthenticationService = new Mock<IAuthenticationService>(); mockAuthenticationService.Setup(m => m.LogIn(It.Is<LoginRequest>(x => x.UserName == "YYY" && x.Password == "ZZZ"))) .Returns(new LoginResponse { Status = StatusCode.OK, IsAuthenticated = true }); var returnUrl = "http://home"; var model = new LoginViewModel { UserName = "******", Password = "******", }; var controller = new AccountController(mockAuthenticationService.Object, null, null); // mock the UrlHelper var requestContext = new RequestContext(this.mockContext.Object, new RouteData()); controller.Url = new UrlHelper(requestContext); // act var result = controller.LogIn(model, returnUrl) as RedirectToRouteResult; // assert Assert.IsNotNull(result); Assert.AreEqual("Index", result.RouteValues["action"]); Assert.AreEqual("Home", result.RouteValues["controller"]); }
public void Login_Post_ServerError() { // arrange var mockAuthenticationService = new Mock<IAuthenticationService>(); mockAuthenticationService.Setup(m => m.LogIn(It.IsAny<LoginRequest>())) .Returns(new LoginResponse { Status = StatusCode.InternalServerError, IsAuthenticated = false }); var controller = new AccountController(mockAuthenticationService.Object, null, null); // act var result = controller.LogIn(new LoginViewModel(), string.Empty) as ViewResult; // assert Assert.IsNotNull(result); Assert.IsFalse(result.ViewData.ModelState.IsValid); }
public void Login() { // arrange var mockAuthenticationService = new Mock<IAuthenticationService>(); var returnUrl = "xxxx"; var controller = new AccountController(mockAuthenticationService.Object, null, null); // act var result = controller.LogIn(returnUrl) as ViewResult; // assert Assert.IsNotNull(result); Assert.AreEqual(string.Empty, result.ViewName); Assert.AreEqual(returnUrl, result.ViewData["returnUrl"]); }