Populate IConfiguration for unit tests

前端 未结 5 820
别那么骄傲
别那么骄傲 2021-01-17 07:37

.NET Core configuration allows so many options to add values (environment variables, json files, command line args).

I just can\'t figure out and find an answer how

5条回答
  •  被撕碎了的回忆
    2021-01-17 08:03

    Would AddInMemoryCollection extension method help?

    You can pass a key-value collection into it: IEnumerable> with the data you might need for a test.

    var builder = new ConfigurationBuilder();
    
    builder.AddInMemoryCollection(new Dictionary
    {
         { "key", "value" }
    });
    

提交回复
热议问题