I'm trying to get my head around using Nunit, Ninject, MVC2 and the ADO.Net Entity Data Model.
Let's say I have have a ProductsController instantiating a SqlProductsRepository class.
public class ProductsRepository : IProductsRepository
{
public MyDbEntities _context;
public ProductsRepository()
{
_context = new MyDbEntities();
}
public IList<Product> GetAllProducts()
{
return (from p in _context.Products select p).ToList();
}
}
public class ProductsController : Controller
{
public ActionResult ProductsList()
{
ProductsRepository r = new ProductsRepository();
var products = r.GetAllProducts();
return View(products);
}
}
I'd like to be able to perform unit testing on ProductsRepository to ensure this is returning the correct data but i'm not sure how to write the Test Class.
Every tutorial/document I've read so far points me to creating a Mock object using IProductsRepository and then injecting and testing the Controller.
This seems, to me, to bypass the concrete implementation.
MyDbEntities comes from an ADO.Net Entity Data Model .edmx