testing the controller in asp.net mvc
Posted
by csetzkorn
on Stack Overflow
See other posts from Stack Overflow
or by csetzkorn
Published on 2010-05-19T13:57:58Z
Indexed on
2010/05/19
14:00 UTC
Read the original article
Hit count: 229
asp.net-mvc
|s#arp-architecture
Hi,
I would like to test the validation of submitted DTO. This is the bare bone of a controller create action:
[AcceptVerbs(HttpVerbs.Post)]
public RedirectToRouteResult Create(SomeDTO SomeDTO)
{
SomeObject SomeObject = null;
try
{
SomeObject = this.RepositoryService.getSomeObjectRepository().Create(SomeDTO, this.RepositoryService);
}
catch (BrokenRulesException ex)
{
ex.AddModelStateErrors(ModelState, "Model");
}
catch (Exception e)
{
ModelState.AddModelError("Exception", e.Message);
}
TempData["ViewData"] = ViewData;
TempData["SomeDTO "] = SomeDTO;
return ModelState.IsValid ? RedirectToAction("SomeObjectDetail", new { Id = SomeObject.Id }) : RedirectToAction("Form");
}
The mechanics , although not relevant, is as follows: I have a strongly typed view = form which submits a dto to this action which either returns the form or the details page of the created object.
I would like to unit test whether the Model contains certain key/errorMessage combinations given some invalid dto. Did someone do similar stuff? Any pointers would be very much appreciated.
Thanks.
Best wishes,
Christian
© Stack Overflow or respective owner