Joni Moilanen
Joni Moilanen's Blog

Joni Moilanen's Blog

Welcome to my new blog!

Joni Moilanen's photo
Joni Moilanen
·Dec 15, 2021·

1 min read

I haven't blogged for years and due to some changes in my career, I have decided to start again!

As I focus 100% on Microsoft development stack (Azure, .NET/C# etc), my content will focus mostly on those areas, but there will be platform-agnostic, too.

I have no grand plan for the topics itself, but one goal is to write useful tips and tricks, best practices etc to myself, so that I can get back to them later, if needed. Hopefully you'll find them useful, too!

Without further ado (ah, the old, good days of ADO), here is the first tip for any .NET-project with configuration:

If you need to setup IConfiguration for dependencies when unit testing, you can utilize the InMemoryCollection

private IConfiguration CreateTestConfig()
{
      var testConfiguration = new Dictionary<string, string>
      {
           {"SampleKey", "Value1"},
           {"AppSettings:Key", "Value2"} //Nested settings
      };

      var configuration = new ConfigurationBuilder()
           .AddInMemoryCollection(testConfiguration) 
           .Build();

      return configuration;
      }
 
Share this