I'm brand new to unit testing and I need to do this for a current project. I have plenty of examples for testing model classes and MVC controllers, but I have a couple of web API controllers that have a Json return that I need to unit test. What should I be testing with these, and how can I do that?
First example taking no parameters
public class DefaultController : ApiController
{
private TestEntities db = new TestEntities();
[AcceptVerbs("GET")]
public IHttpActionResult FirstAPI()
{
var myQuery = (from p in db.Participants
select new
{
p.ID,
p.Name,
p.MemberType
});
return Json(myQuery);
}
}
Second example taking two parameters
public class DefaultController : ApiController
{
private TestEntities db = new TestEntities();
[AcceptVerbs("GET")]
public IHttpActionResult SecondAPI(int id, string name)
{
var myQuery = (from p in db.Participants
where p.ID == id && p.Name == name
select new
{
p.ID,
p.Name,
p.MemberType
});
return Json(myQuery);
}
}