.NET Core 2.0
Create a new configuration and specify the correct path for your appsettings.json.
This is part of my TestBase.cs that I inherit from all of my tests.
public abstract class TestBase
{
protected readonly DateTime UtcNow;
protected readonly ObjectMother ObjectMother;
protected readonly HttpClient RestClient;
protected TestBase()
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json")
.Build();
var connectionStringsAppSettings = new ConnectionStringsAppSettings();
configuration.GetSection("ConnectionStrings").Bind(connectionStringsAppSettings);
UtcNow = DateTime.UtcNow;
ObjectMother = new ObjectMother(UtcNow, connectionStringsAppSettings);
WebHostBuilder webHostBuilder = new WebHostBuilder();
webHostBuilder.ConfigureServices(s => s.AddSingleton<IStartupConfigurationService, TestStartupConfigurationService>());
webHostBuilder.UseStartup<Startup>();
TestServer testServer = new TestServer(webHostBuilder);
RestClient = testServer.CreateClient();
}
}
source
share