I have a very simple scenario:
[HttpGet]
public ActionResult CreateUser()
{
return View();
}
[HttpGet]
public ActionResult Thanks()
{
return View();
}
[HttpPost]
public ActionResult CreateUser(CreateUserViewModel CreateUserViewModel)
{
if (ModelState.IsValid)
{
return View("Thanks");
}
return View(CreateUserViewModel);
}
My unit test uses the testhelper from mvc contrib:
[Test]
public void UserController_CannotCreateUserWithNoLastName()
{
// arrange
UsersController UsersController = new UsersController();
CreateUserViewModel CreateUserViewModel = new CreateUserViewModel();
CreateUserViewModel.LastName = "";
// act
ActionResult result = UsersController.CreateUser(CreateUserViewModel);
// assert
result.AssertViewRendered().ForView("CreateUser");
}
When I open the browser and try to submit an invalid user (no lastname) it redirects to the createuser form but the unit test fails (it says that it redirects to thanks). Why is this? Can anyone see anything wrong? Thanks!