In running my VS2008 unit integration tests against my DAL, I have found that the assembly is reading machine.config instead of the assembly’s app.config.
Here’s the rundown on the call stack:
- Unit Test Project has method calling into a DataLayer Project
MyDataLayerclass inherits from a base class. Method is calledGetStuff()- Base class is using
System.Configuration. All good. - calling this property in code:
ConfigurationManager.ConnectionStrings['MyConnStr']actually returns null because it’s not found apparently. - checking the
MyDataLayerclass, yep, MyConnStr is there. - checking the collection
ConnectionStrings, yes, it has one connection string. It’s the one in machine.config that’s over inC:\Windows\Microsoft.NET\Framework\v2.0.50727\Config\machine.config - I am not sure why my DAL’s
app.configis being superseded by themachine.config
Any help is appreciated!
Not sure if this applies to you, but you need to make sure the configuration string is in your Unit Test Project’s app.config, not your DataLayer project.