I am writing Unit Tests using NUnit
. This is my Class under test looks like
public class CustomerService
{
private readonly IConfiguration _configuration;
// ctor
CustomerService(IConfiguration configuration)
{
}
}
Unit Test of the above class.
public class CustomerServiceTests
{
private readonly IConfiguration _configuration;
CustomerServiceTests()
{
_configuration = GetConfiguration();
}
public static IConfiguration GetConfiguration(string outputPath="")
{
return new ConfigurationBuilder()
.SetBasePath(outputPath)
.AddJsonFile("appsettings.json", optional: true)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true)
.Build();
}
}
Now I need to get the path of the appsettings.json
directory which is present in the StartUp (API
) project
This is my how project directory looks like
CustomerProject
-customer.api
-customer.services
-customer.services.test
How do I get the path of customer.api
project which is containing the appsettings.json
?