问题
I need to test my ASP.NET Core routes and other configuration of my IWebHost
, along with WebSocket
code. For this I believe actually hosting Kestrel within my automated tests is the best approach.
How can I host configure the IWebHost
such that it listens to an HttpMessageHandler
that I have prepared instead of listening on an actual port so I can mock up messages handed to it?
Or is there a better way?
I can't even find a property that discloses which port it listens to by default.
回答1:
you can use this package Microsoft.AspNetCore.TestHost
from nuget.This article will help you. https://docs.microsoft.com/en-us/aspnet/core/testing/integration-testing
来源:https://stackoverflow.com/questions/49740003/how-to-host-the-kestrel-server-in-a-test