I have connection strings set up in an app.config file, with different files for debug and release based on this SO answer. I'm setting up an integration test project which should be using a different initial catalog for the tests. How do I get the project, and only the integration test project, to use a different connection string?
Edit: Trying to add some more detail. In app.config I have the following:
In the connection string, it has the line initial catalog=MyProgramDB. However I'd like unit tests to use initial catalog=MyIntegrationTestingDB instead.
I tried creating a separate configuration for testing I can switch to, but I can't change the testing projects to any configuration except Debug or Release.
You didn't specify any code, so I will give you an example of how to initialize it with SQL Server and EF.
In your project Startup, you will need to inject the connection string.
It might be something like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("<Name1>"));
}
The <Name1> will be the connection string that you want for the integration tests. In another project, you might use <Name2>.