❔ WebApplicationFactory and integration tests
I've run into an issue with my integration tests and I'm looking for some insight. I'm using
WebApplicationFactory
and trying to set up a configuration inside it. Here's what it looks like:
Now, I have a separate setup in my Program.cs
file, where I am adding some services including DbContexts. Here's how it looks:
My AddDbContexts
method is actually adding contexts using UseNpgsql
and it takes the connection string from my configuration.2 Replies
Here's the tricky part: my
ConfigureAppConfiguration
is called after the Program.cs
so at the point when I need the connection strings, they are null. I tried to solve this by moving my configuration setup to IHostBuilder.ConfigureAppConfiguration
instead of IWebHostBuilder.ConfigureAppConfiguration
, but it didn't work. I feel like I'm missing something basic here. Any advice or pointers would be really appreciated. Thanks!Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.