I’m just learning ASP.NET MVC and I’m trying to create a mock form request for a unit test.
I’m using RhinoMocks.
I have looked at the following websites but cannot get these to work.
http://blog.maartenballiauw.be/post/2008/03/19/ASPNET-MVC-Testing-issues-Q-and-A.aspx
Update: Controller Code:
/// <summary>
/// Creates a new entry
/// </summary>
/// <returns></returns>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind()]Person person)
{
if (Request.Form["DateOfBirth"].ToString() == "")
{
TempData["message"] = "Please select a date of Birth";
ViewData["DateOfBirth"] = Request.Form["DateOfBirth"].ToString();
MvcValidationAdapter.TransferValidationMessagesTo(ViewData.ModelState, person.ValidationMessages);
return View();
}
else
{
if (person.IsValid())
{
person.DateOfBirth = Convert.ToDateTime(Request.Form["DateOfBirth"]);
personRepository.SaveOrUpdate(person);
TempData["message"] = person.Firstname + " was successfully added";
return RedirectToAction("Create", "OrderDetails", new { id = person.ID });
}
else
{
ViewData["DateOfBirth"] = Request.Form["DateOfBirth"].ToString();
MvcValidationAdapter.TransferValidationMessagesTo(ViewData.ModelState, person.ValidationMessages);
return View();
}
}
}