I have a controller that is working in my site but failing during unit testing. It is pretty simple and depends on Linq to Sql to return a collection of JSON objects.
The Test fails because the DataContext can't find the connection string when called from outside the MVC project.
I had a look in the auto generated code:
public DC():
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}
The web project can find the "myConnectionString" entry in web.config, but the test project can't find it. The error message I got was:
Test method MyMVCApp.Controllers.HomeControllerTest.IndexShouldReturnIssues threw exception: System.NullReferenceException: Object reference not set to an instance of an object..
I don't want to pass another connection string in from my unit tests because I want to test that the connection string in the web.config works.
Thanks, John