asp.net - How do I share settings between web.config and class library during unit testing? -
i want unit tests in class library, need same config settings in main asp.net project's web.config. therefore need duplicate number of web.config settings class library.
i have added settings through class library's project properties settings tab.
then app.config file automatically added project:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <sectiongroup name="applicationsettings" type="system.configuration.applicationsettingsgroup, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" > <section name="externalservices.cpr.properties.settings" type="system.configuration.clientsettingssection, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" requirepermission="false" /> </sectiongroup> </configsections> <applicationsettings> <externalservices.cpr.properties.settings> <setting name="cprprodhostname" serializeas="string"> <value>direkte.cpr.dk</value> </setting>
question 1. "best practice" way share/duplicate settings main web.config class library needs run unit tests separately same config?
question 2. want read settings name. try read configurationmanager.appsettings["cprprodhostname"]; (using system.configuration;) doesn't work, returns null?
question 3. purpose of app.config-file? because there no build action set , file not copied output, never visible anywhere default. implies can not change these settings in run time. that's quite strange, right?
hope talking web config setting below:
<configuration> <appsettings> <add key="hostname" value="www.hostname.com" /> </appsettings> </configuration>
please check above part , use below code retrieve key value of hostname
configurationmanager.appsettings["hostname"]
it requires using system.configuration;
Comments
Post a Comment