title: How to read appsettings.json in xunit test project?
body: <p>I am trying to write the test cases for one of the method written in MVC controller and in that method I am reading AppSettings.json file. as below</p>
  <pre><code>public class MemberController : ControllerBase
  {
      IMemberRepository _memberRepository;
      public PayPalKeys payPal;
      public ActiveDirectory activeDirectory;
      private static GraphServiceClient _graphServiceClient;
      public MemberController(IMemberRepository member, IOptions&lt;PayPalKeys&gt; payPal, IOptions&lt;ActiveDirectory&gt; activeDirectory)
      {
          _memberRepository = member;
          this.payPal = payPal.Value;
          this.activeDirectory = activeDirectory.Value;
      }   
      
      private IConfigurationRoot LoadAppSettings()
      {
          try {
              var config = new ConfigurationBuilder()
              .SetBasePath(System.IO.Directory.GetCurrentDirectory())
              .AddJsonFile(&quot;appsettings.json&quot;, false, true)
              .Build();
              -
              -
              -
          }
          catch(Exception ae){}
      }
  }
  </code></pre>
  <p>and the below is my Test code</p>
  <pre><code>[Fact]
  public void Payment()
  {
      var memberRepositoryManagerMock = new Mock&lt;IMemberRepository&gt;();     
      var members = new Members() {};
      var controller = new MemberController(memberRepositoryManagerMock.Object, GetPayPalConfigurationMock().Object, GetActiveDirectoryConfigurationMock().Object);
      var result = controller.MakePayment(members);
  }
  </code></pre>
  <p>and that method from controller gives the exception as</p>
  <blockquote>
  <p>The configuration file 'appsettings.json' was not found and is not optional. The physical path is 'F:\API.Test\bin\Debug\netcoreapp2.2\appsettings.json'.</p>
  </blockquote>
  <p>Here I am not understanding that how to mock that &quot;appsettings.json&quot; part in the test case code.</p>