AdvertisementDataContext db = new AdvertisementDataContext(); //make an object so that we can retrieve data from database
public ActionResult Index()
{
var advertisement = db.Advertisements.ToArray(); // retrieve data from database
return View(advertisement); // we return the object to the index view
}
我为此代码编写了一个测试用例。但它不起作用,它给出了错误
Error 1 The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
我的测试方法是
[TestMethod]
public void TestIndex() {
Bartering.Models.AdvertisementDataContext db = new Bartering.Models.AdvertisementDataContext();
AdvertisementController controller = new AdvertisementController();
ViewResult result = controller.Index() as ViewResult;
Assert.AreEqual(db.Advertisements, result.ViewBag);
}
请帮我解决这个问题或帮我为该方法编写一个测试用例..