1

I have a C# class library project and I am using appsettings.json to read values.
I have one MS Test (unit test) project and I am maintaining another appsettings.json file

appsettings.json file in C# Class library project:

{
  "name" : "jack"
}

appsettings.json file in MS Test project:

{
  "name" : "Mike"
}

My requirement is when I run the unit test the value "name" in the appsettings.json file in the C# class library project needs to be replaced with appsettings.json file in the MS Test project.

Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • Check the post https://stackoverflow.com/questions/38398022/access-from-class-library-to-appsetting-json-in-asp-net-core If it is helpful for you. – Prajakta.S Dec 15 '20 at 19:33

1 Answers1

0

You should be using dependency injection to access configuration settings in your lib's classes; simply manually construct an instance of the configuration class with the test values you desire and pass it to the lib classes' constructors.

Moho
  • 15,457
  • 1
  • 30
  • 31