Reputation: 11341
my project in the web.config file
...
<add name="fooDBContext"
connectionString="Data Source=foo;Initial Catalog=WebData;User Id=scpauser;Password=password;" providerName="System.Data.SqlClient" />
</connectionStrings>
My unit test which is in a separate project
namespace unit_tests.ModelTests
{
[TestClass]
public class CAMADBContextTest
{
[TestMethod]
public void TestMethod1()
{
Database.SetInitializer<mvc3test.Models.CAMADBContext>(null);
var db = new mvc3test.Models.CAMADBContext();
var dps = db.DataProperty.Where(p => p.AccountNumber == 141);
}
}
}
Upvotes: 1
Views: 239
Reputation: 478
For similar situation in my project I added config entries from web.config in web application to App.config in unit test project. Then I didn't need to do any change in code to read config entry and it worked same as in web application.
Upvotes: 1