Hello @Brett McDonald , thanks for reaching out to us, your question is appreciated.
You can use Microsoft.AspNetCore.Mvc.Testing
package to achieve this scenario. I have done a quick setup to show you how to do this.
As I understand, you want to call GenericWebHostBuilder.ConfigureAppConfiguration
method in your Unit Tests using XUnit
. To do this please follow below steps:
- Run the below command to add
Microsoft.AspNetCore.Mvc.Testing
package in your Test project:
The packages includes adotnet add package Microsoft.AspNetCore.Mvc.Testing
WebApplicationFactory<TEntryPoint>
class which is used to bootstrap the API in memory. This is convenient, as we don't need to have the API running before we run these tests. - Inject
WebApplicationFactory<Api.Startup>
in your constructor like below: - Run the test. This will call
CreateHostBuilder
in yourProgram.cs
, and thus,ConfigureAppConfiguration
method will be called. Please see the call stack of this below:
*If you want to create custom WebApplicationfactory
, you can check out this article as it has detailed and step-by-step process to do that. *
----------
Please do not forget to "Accept the answer" if this response answers your query. This will help others in the community as well.