May I enquire if I am mocking my IConfiguration correctly as I keep get a null error. I am trying to mock my controller where it reads the appsettings.json.
Controller.cs
private readonly IConfiguration _configuration;
public Controller(IConfiguration configuration)
{
_configuration = configuration;
}
public void methodOne()
{
string directory = _configuration.GetValue<string>("section:value");
}
ControllerTest.cs
public class ControllerTest: ControllerTestsBase<Controller>
{
public ControllerTest()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");
Configuration = builder.Build();
}
[Fact]
public void TestOne()
{
Controller.methodOne();
}
}
When I debug and trace to the Controller.cs methodOne, the _configuration keeps prompted null error.
- Apologies for the snippet of code, I have updated the code again.