I want to be able to write test code. But my Action is coupled to my DataContext. How can I remove dependency?
public ViewResult About()
{
var db = new CamaDataContext();
var item = new PropertyViewModel();
AutoMapper.Mapper.Map(db.dataProperty.FirstOrDefault(),item);
return View(item);
}
Use a dependency injection framework such as ninject or structuremap to pass it in through the controller’s constructor, then when you’re writing your tests you can pass those dependencies in thought constructor.
This would also provide you the opportunity to mock those depenedencies out and not actually have to make calls to your database while testing