Reputation: 11
I having a functional CRUD app that (simply put) creates, reads, updates, and deletes teachers from a localdb through a GUI.
Regarding create, I have two action results located in the controller:
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(ModelTeacher oTeacher)
{
if (!ModelState.IsValid)
{
// Return to the view with the validation error messages
return View(oTeacher);
}
db.DbTeachers.Add(oTeacher);
db.SaveChanges();
return RedirectToAction("SuccessCreate", "Teacher");
}
I haven't found resources that click with me on how to test CRUD. I prefer to do an integration test and go through the motion of CRUD so the final test (delete) will remove it from the database. I feel a mock database is not necessary because it is such a small localdb.
My idea to test this controller is to recreate a controller in a test project, create a teacher, and find it and assert it is not null. But it appears that setting up a test environment is not that simple.
Upvotes: -3
Views: 75
Reputation: 233347
If the application mostly does CRUD operations, there's little to be gained from separating what little application code you may have from the database. In that case, I'd consider a self-hosted integration test suite the best fit.
Essentially:
My article Closing database connections during test teardown contains various links to further reading and sample code bases.
Upvotes: 1