c# - ConfigurationManager.AppSettings Returns Null In Unit Test Project -



c# - ConfigurationManager.AppSettings Returns Null In Unit Test Project -

i have c# unit test project application settings in app.config file. testing class exists in different project. class depends on both, configurationmanager.appsettings , configurationmanager.connectionstrings.

the project class beingness tested resides in not have app.config file. have thought because class beingness instantiated in context of unit test project utilize unit test project's app.config file. indeed, seem case connection string.

the class retrieves connection string without issues. however, when class tries retrieve application settings configuration manager returns null. going on here?

edit 1

i thought maybe thought seek load settings in test project see happens. tried load setting in unit test before calling code instantiates class in external project. same result, nothing. guess can exclude other project equation time being.

here excerpt config file:

<configsections> <sectiongroup name="applicationsettings" type="system.configuration.applicationsettingsgroup, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" > <section name="mynamespace.properties.settings" type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </sectiongroup> </configsections> ... <applicationsettings> <mynamespace.properties.settings> <setting name="bing_key" serializeas="string"> <value>...</value> </setting> </mynamespace.properties.settings> </applicationsettings>

and here how attempting load setting:

string test = system.configuration.configurationmanager.appsettings["bing_key"];

you mentioned settings in project properties. see if can access setting way:

string test = properties.settings.default.bing_key;

you may need executing assembly of project settings file defined, seek first.

edit

when using visual studio's project settings file, adds stuff app.config , creates app.config if not present. configurationmanager can't touch these settings! can these specific generated project.settings file using above static method. if want utilize configurationmanager, need hand write app.config. add together settings so:

<appsettings> <add key="bing_api" value="whatever"/> </appsettings>

c# visual-studio unit-testing app-config application-settings

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -