I'm trying to run an NUnit test on a method that obtains a connectionstring from the web.config file. When I test it, it obviously crashes when trying to pull that connection string. So I poked around and came to this URL:
Unit testing the app.config file with NUnit
Here is the code the user posted:
void BasicSetup()
{
ConnectionStringSettings connectionStringSettings = new ConnectionStringSettings();
connectionStringSettings.Name = "testmasterconnection";
connectionStringSettings.ConnectionString = "server=localhost;user=some;database=some;port=3306;";
ConfigurationManager.ConnectionStrings.Clear();
ConfigurationManager.ConnectionStrings.Add(connectionStringSettings);
}
That almost seemed to be the answer I was looking for. When I actually put in the code, I get the following error: Failure: System.Configuration.ConfigurationErrorsException : The configuration is read only.
Is there something else I must do first? Thanks!