I am trying to test my MVC project. For the sake of simplicity, in the Startup
class I have:
public static IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
// Setup configuration sources.
var configuration = new Configuration()
.AddJsonFile("config.json");
Configuration = configuration;
}
And I am using this configuration globally, like this:
private static string connectionString = Startup.Configuration["Database:ConnectionString"];
It works, it can find this in the file.
My problem:
When I am running tests, the Startup
class seems to not be firing. Because of that whenever I access Startup.Configuration
, this field is null.
What can I do to fire it so that the config.json
file is read? Or how else could I solve this issue?