Skip to content

Instantly share code, notes, and snippets.

@guojianwei001
Last active July 7, 2022 08:33
Show Gist options
  • Save guojianwei001/85de82cff732c611cc5c697e2324b8e7 to your computer and use it in GitHub Desktop.
Save guojianwei001/85de82cff732c611cc5c697e2324b8e7 to your computer and use it in GitHub Desktop.
Create a in-memory json configuraiton that is used to mock IConfiguration.
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