How to host the Kestrel server in a test?

时光毁灭记忆、已成空白 提交于 2019-12-25 01:37:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!