私はVS2010のユニットテスト機能で構築されたマイクロソフトを勉強中で、問題を見つけました。ユニットテストMVC 3とエンティティフレームワーク
[TestClass]
public class HomeControllerTest
{
[TestMethod]
public void SomeTest()
{
//Arrange
HomeController controller = new HomeController();
//Act
ViewResult results = controller.Index() as ViewResult;
//Assert
ViewDataDictionary viewData = results.ViewData;
Assert.AreEqual(null, viewData["Message"]);
}
}
これは失敗しますが、問題ではありません。しかし、問題は何ですか?EntityFrameworkモデル「myModel.edmx」にエラーが発生しています。"System.ArgumentException: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid."
これはファイルMyModel.Designer.csにあります。問題の行は次のとおりです:
public Tool_Entities() : base("name=Tool_Entities", "Tool_Entities") { this.ContextOptions.LazyLoadingEnabled = true; OnContextCreated(); }
私はこの行が大丈夫ですが、私がテストプロジェクトを実行していないときは、このモデルを正常に接続できます。
この記事を見てください:http://bit.ly/bF7jL3。 O/RMの周りに(LINQ対応の)抽象化を構築する方法について説明します。 – Steven
あなたのテストは別のプロジェクトですか? (その場合、テストは独自のapp.configを実行します) –