Using Linq to sql and server explorer, I mapped to a loginvalidation stored proc. So I write the following code:
ClientReportingDataContext db = new ClientReportingDataContext();
var data = db.ADMIN_LoginValidation(login, password);
It throws up an exception on the following line:
public ClientReportingDataContext() :
base(global::System.Configuration.ConfigurationManager.ConnectionStrings["FeedsConnectionString"].ConnectionString, mappingSource)
Exception thrown:
Object reference not set to an instance of an object.
I’m calling this function from a unit test class. I cann feedsconnectionstring in web.config.
I put the web.config in the unit tests folder, and also under debug and debug/bin. Not sure what I’m missing.
Thanks in advance for any advise.
For a unit test,
won’t be reading from your
web.configfile; it will be reading from the application configuration file for the test runner. Therefore, unless you’ve putFeedsConnectionStringin the application configuration file for your test runner,is
nulland sois going to throw a
NullReferenceException.This is why testing and application configuration files don’t get along well.
You should consider the following:
Then inject your connection string in your test.