title: How to mock IConfiguration.GetValue
body: <p>I tried in vain to mock a top-level (not part of any section) configuration value (.NET Core's IConfiguration).  For example, neither of these will work (using NSubstitute, but it would be the same with Moq or any mock package I believe):</p>
  <pre class="lang-cs prettyprint-override"><code>var config = Substitute.For&lt;IConfiguration&gt;();
  config.GetValue&lt;string&gt;(Arg.Any&lt;string&gt;()).Returns(&quot;TopLevelValue&quot;);
  config.GetValue&lt;string&gt;(&quot;TopLevelKey&quot;).Should().Be(&quot;TopLevelValue&quot;); // nope
  // non generic overload
  config.GetValue(typeof(string), Arg.Any&lt;string&gt;()).Returns(&quot;TopLevelValue&quot;);
  config.GetValue(typeof(string), &quot;TopLevelKey&quot;).Should().Be(&quot;TopLevelValue&quot;); // nope
  </code></pre>
  <p>In my case, I also need to call <code>GetSection</code> from this same config instance.</p>