Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on debugging unit test function in mvc 4(.NET) exception of 'The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid' is generated.

What I have tried:

i have tried to add web.config file to my unit test folder but Still giving same error.
Posted
Comments
Richard Deeming 20-Aug-16 7:54am    
A unit test project isn't a website, so it doesn't know what to do with a web.config file. Try adding an app.config file to the unit test project, and copying the <connectionStrings> element from the web.config file.
Member 10418330 21-Aug-16 2:57am    
It is done but i am actually calling a function in my website .cs file which is using the configuration settings in web.config file.
F-ES Sitecore 22-Aug-16 3:58am    
Your code isn't unit-testable then. You need to refactor it such that it doesn't need a connection string. This is normally done by using a repository pattern and interfaces where your code calls the proper class but you use a mocked version of the repository in your unit tests.

If you read some articles about unit testing you'll see these topics covered with examples.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900