I have an ASP.NET Core 8 Web API project which contains the following setting files:
appsettings.jsonappsettings.Local.json
Following the instructions here, I also have a test project to run an in-memory test server. So far with only this configuration:
var factory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
});
builder.ConfigureTestServices(services =>
{
});
builder.ConfigureAppConfiguration(config =>
{
config.AddConfiguration(Configuration);
});
});
The problem is that when the test project runs the in-memory test server. It is picking up the appsetting.json instead the appsettings.Local.json file from the ASP.NET Core Web API project.
var builder = WebApplication.CreateBuilder(args);
//...some services registration here
builder.Cofiguration["ConnectionsStrings:MyData"] // This reads the value from "appsettings" instead "appsettings.Local"
var app = builder.Build();
How can I configure the test project to so the Program.cs is loaded with the appsettings.Local.json values?