MVC Unit Testing a controller
I have a controller with the Authorize
attribute:
public CustomerController:Controller
{
[Authorize]
public ActionResult GetCustomer(int id)
{
var model=db.Customers.where(c=>c.id==id);
return View(model);
}
}
M开发者_运维技巧y question is, how can I test a controller with the Authorize
attribute?
Do we need to get user information like username and password before testing from HttpContext
?
Are mocks, dependency injection, and inversion of control related to unit testing? If so, can you guys suggest some websites or documents for learning these topics?
Here's some good examples of testing with mocks, DI, IoC, MVC @
http://code.google.com/p/sutekishop/source/browse/trunk/Suteki.Shop/Suteki.Shop.Tests/#Suteki.Shop.Tests%2FControllers
The author doesn't use the Authorize attribute but uses custom action filters and roles based security I believe.
精彩评论