public void LogOn_Post_ReturnsViewIfValidateUserFails() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, null); // Assert Assert.That(result, Is.InstanceOf(typeof(ViewResult))); ViewResult viewResult = (ViewResult)result; Assert.That(viewResult.ViewData.Model, Is.EqualTo(model)); Assert.That(controller.ModelState[""].Errors[0].ErrorMessage, Is.EqualTo("The user name or password provided is incorrect.")); }
public void LogOn_Post_ReturnsRedirectToHomeOnSuccess_WithExternalReturnUrl() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "http://malicious.example.net"); // Assert Assert.That(result, Is.InstanceOf(typeof(RedirectToRouteResult))); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.That(redirectResult.RouteValues["controller"], Is.EqualTo("Home")); Assert.That(redirectResult.RouteValues["action"], Is.EqualTo("Index")); // TODO: Mocking Framework Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); }
public void LogOn_Post_ReturnsViewIfModelStateIsInvalid() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; controller.ModelState.AddModelError("", "Dummy error message."); // Act ActionResult result = controller.LogOn(model, null); // Assert Assert.That(result, Is.InstanceOf(typeof(ViewResult))); ViewResult viewResult = (ViewResult)result; Assert.That(viewResult.ViewData.Model, Is.EqualTo(model)); }
public void LogOn_Post_ReturnsRedirectOnSuccess_WithLocalReturnUrl() { // Arrange AccountController controller = GetAccountController(); LogOnModel model = new LogOnModel() { UserName = "******", Password = "******", RememberMe = false }; // Act ActionResult result = controller.LogOn(model, "/someUrl"); // Assert Assert.That(result, Is.InstanceOf(typeof(RedirectResult))); RedirectResult redirectResult = (RedirectResult)result; Assert.That(redirectResult.Url, Is.EqualTo("/someUrl")); // TODO: Mocking Framework Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignIn_WasCalled); }