I've been trying to read an app.config file during unit testing following the instructions in this Using a Configuration File to Define a Data Source using Visual Studio 2010. I've read numerous posts here in the forum as well, but I'm still getting a null value when trying to read the app.config values. Below are snippets of my app.config and unit test code.
App.config
<configuration>
<configSections>
<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</configSections>
<connectionStrings>
<add name="DatabaseConnectionString" connectionString="Data Source=***;User Id=***;Password=***;Integrated Security=no" providerName="Oracle"/>
</connectionStrings>
<microsoft.visualstudio.testtools>
<dataSources>
<add name="MyOracleConnection" connectionString="DatabaseConnectionString" dataTableName="***" dataAccessMethod="Sequential"/>
</dataSources>
</microsoft.visualstudio.testtools>
</configuration>
Unit Test:
[TestMethod()]
[DeploymentItem("app.config")]
public void S_ConstructorTest(){
myObject m = new myObject();
...}
In my object code I'm attempting to read the config file via:
public static readonly string sConnectionString = System.Web.Configuration.WebConfigurationManager.AppSettings["sConnectionString"];
Based on what I've read in other posts here, MSDN seems to add more than is necessary for this to work, however I still keep getting null values when reading the config file. I know that there's a debate as to whether or not unit testing should access a real DB but for now I just need to get it to read the config file.
Any help would be appreciated.