Hi
I’ve taken over an ASP.NET MVC project from a colleague. I have only a rudimentary knowledge of both ASP.NET MVC and unit testing.
I’m trying to get off on the right foot by creating unit tests. I thought I’d start with testing a controller. Unfortunately I stumbled at the first hurdle! The controller in question has the Authorize attribute and dependencies that are injected via dependency injection (Unity).
The controller looks something like:
namespace Project.Controllers
{
[Authorize( Roles = "Admin,PurchaseOrderUser" )]
public class SomeController : Controller
{
private readonly IOrganisationService _organisationService;
private readonly IPurchaseOrderService _purchaseOrderService;
// Dependency injection will provide these
public SomeController(
IPurchaseOrderService purchaseOrderService,
IOrganisationService organisationService)
{
_purchaseOrderService = purchaseOrderService;
_organisationService = organisationService;
}
// List Purchase Orders
public ActionResult Index( )
{
Return View();
}
// Rest of controller....
So, using nUnit and Rhino Mock Mocks how can I test the Index action?
Thanks.
Alan T