jeudi 28 mars 2019

Kestrel server is not accessable after IWebHost.Start

I have set of xUnit tests that have to make requests to running Kestrel servers. These tests are placed in .Net Core App project. There is a code that runs the only once before tests in the beginning and has to run Kestrel servers on the specific ports.

So I need that my servers were runned and tests were passed. For my server host I have the next code:

WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel()
.UseUrls("http://*:8000")
.UseContentRoot(Directory.GetCurrentDirectory())
.Build()

  • If I run server via IWebHost.Run then main thread is blocked and tests are not performed. But server starts and is able to get requests
  • If I run server via IWebHost.Run in the separate thread then nothing happens (there is no server port in list of ports of netstat -a)
  • I got the same effect If I use IWebHost.Start in separate thread
  • And if I use just IWebHost.Start then main thread is not blocked, there is a port in the list of ports but server doesn't respond to request from browser

Is there a way to run Kestrel server from .Net Core App test project and perform tests?

Aucun commentaire:

Enregistrer un commentaire