How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

前端 未结 5 1445
傲寒
傲寒 2020-12-23 16:02

We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5.

There are some unit tests that depend on a database. Setting up the app.config file in the

5条回答
  •  忘掉有多难
    2020-12-23 16:42

    Keep in mind that for a test project:

    AttachDBFilename=|DataDirectory|
    

    means it will look in your output /bin/debug folder for a unit test as opposed to the App_Data folder in your web/production/whatever app.

    You need to do two things 1. Move the database file OUT OF your App_Data folder to your root of your test app. 2. Highlight your database so you get your properties window in Visual Studio. Set the build action to "Content" so it will get copied to your output folder when you run the project.

    Voila.

提交回复
热议问题