Lets say i have the following controller:
//
// GET: /Courses/Edit/5
public ActionResult Edit(int id)
{
Course course = courseService.GetCourseByID(id);
if (course != null && course.userCanAccess())
{
// Do stuff...
}
}
The if statement is designed as a simple check to ensure the user can go ahead with the action. The Course entity itself provides the logic to determine if the user can access it. This works well but does lead me to a problem: how to test the controller.
I need a way to ensure that course.userCanAccess() returns a specific result in my controller test. My entity POCOs do not have interfaces so I don't believe I can mock them (please correct me if this is wrong).
My thinking is I could just create a full Couse object for the test which is configured so that userHasAccess() will return what I want but the method relies on certain related entities of Course being "hydrated" and so could become a chore to wire up.
I am new to testing so am unsure how to proceed.