public ServerFixtures() { IWebHostBuilder builder = Program.CreateWebHostbuilder(Array.Empty <string>()) .UseEnvironment("test") .UseContentRoot(Path.GetFullPath("../../../../PlannerApi")); _server = new TestServer(builder); using (var scope = _server.Host.Services.CreateScope()) { IServiceProvider services = scope.ServiceProvider; try { DbSeeder.InitializeTest( services.GetRequiredService <PlannerContext>() ); } catch (Exception ex) { ILogger <Program> logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } Client = _server.CreateClient(); }