Last active
July 7, 2022 08:33
-
-
Save guojianwei001/85de82cff732c611cc5c697e2324b8e7 to your computer and use it in GitHub Desktop.
Create a in-memory json configuraiton that is used to mock IConfiguration.
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 inMemorySettings = new Dictionary<string, string> | |
{ | |
{"Languages:0", "en"}, | |
{"Languages:1", "cn"}, | |
{"Languages:2", "ar"} | |
{"SectionName:SomeKey", "SectionValue"}, | |
//...populate as needed for the test | |
}; | |
var configuration = new ConfigurationBuilder() | |
.AddInMemoryCollection(inMemorySettings) | |
.Build(); | |
/* | |
references: | |
https://stackoverflow.com/questions/64794219/how-to-mock-iconfiguration-getvalue | |
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-6.0&viewFallbackFrom=aspnetcore-3.0#memory-configuration-provider | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment