views:

37

answers:

1

Hello,

I just started using NUnit to write test cases for my asp.net web application project.

Some of the code written to access database values fetches the ConnectionString from a "section" defined under "configSections" of web.config file.

This works fine during the normal execution of the project on a web browser. But when I access the same method through the test case, WebConfigurationManager.GetSection() always return null.

Initially I was also not able to access AppSettings section of web.config but it got solved when I copied the web.config file into the BIN folder. But still not able to fetch the "section" inside "ConfigSection".

Kindly suggest.

+1  A: 

By default NUnit will look for a config file that has the same name as the dll that contain the tests. So if you have someTests.dll NUnit will want to pick up someTests.dll.config. So for standard exes the trick is to copy your App.config to match the dll name pattern. I think that also works for web apps. You would copy web.config to someTests.dll.config. But to be honest I usually don't write tests that need to get to the config so I don't know for sure.

Mike Two
Thanks for the help but I have also copied and renamed the web.config file to bin directory and this is how appsettings section started to work for me. But I am not able to access the configSections.
araaku
Have you tried just using `ConfigurationManager` instead of `WebConfigurationManager`? Not sure why it would help but it might be worth a try.
Mike Two
ConfigurationManager did not work either.
araaku