Here are the steps to use Microsoft.Extensions.Configuration in your .NET Core unit tests:
- Include the .NET Core Configuration NuGet package: https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/
- Copy the appsettings.json to your test project.
- Don’t forget to set the ‘Copy to output directory’ to ‘Copy always’
- Add the following code to build up your configuration:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var config = new ConfigurationBuilder() | |
.AddJsonFile("appsettings.json") | |
.Build(); |