I am currently working on a pretty simple test libary. The solution also contains an ASP.NET Core Webhost, which processes simple CRUD operations. I want to unit test this ASP.NET Core application without always having to start both projects, so I am creating a new WebHostBuilder inside my NUNit test-libary.
[OneTimeSetUp]
public void SetupHost()
{
var webhostBuilder = new WebHostBuilder()
.UseKestrel()
.UseIISIntegration()
.UseContentRoot("root")
.UseStartup(typeof(Startup))
.ConfigureAppConfiguration((builderContext, config) =>
{
config.AddJsonFile("config1", false);
config.AddJsonFile("config2", false);
});
webhostBuilder
.Build()
.Run();
}
The problem is that SetupHost() never finishes, because Run() blocks the thread until the host shuts down.
How can I start a new webhost, then after it successfully started start my unit tests?
Aucun commentaire:
Enregistrer un commentaire