Reputation: 24182
I am trying to start unit testing an MVC2 project, which uses the Entity Framework. When I run my "hello world" test, it fails saying this:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
How can I pass the connection data (which were generated by the Entity Framework and are in the main Web.config) to the testing project?
Thanks
Upvotes: 0
Views: 312
Reputation: 2744
I would recommended using Dev Magic Fake to Mock the UI without need to use Entity framework or even DB, using Dev Magic Fake, you can run your MVC project and run the unit test without need for any DAL for more information http://devmagicfake.codeplex.com/
Thanks
Upvotes: 0
Reputation: 37483
Depending on what unit testing framework you use you could try adding an app.config to your test-project with the right settings for EF. This works with xUnit.Net and I'm pretty sure most other test-frameworks also support this.
For completeness I do need to warn you that tests that touch the database aren't unit-tests but integration tests. Those are useful too but can become a hassle to maintain when your code changes. It's usually a good idea to test small pieces of code in isolation, this gets around problems like you describe because you won't need to access the database at all.
Upvotes: 4