Integration testing with in-memory IdentityServer

前端 未结 7 1543
一生所求
一生所求 2020-12-07 17:23

I have an API that uses IdentityServer4 for token validation. I want to unit test this API with an in-memory TestServer. I\'d like to host the IdentityServer in the in-memor

相关标签:
7条回答
  • 2020-12-07 17:50

    The trick is to create a handler using the TestServer that is configured to use IdentityServer4. Samples can be found here.

    I created a nuget-package available to install and test using the Microsoft.AspNetCore.Mvc.Testing library and the latest version of IdentityServer4 for this purpose.

    It encapsulates all the infrastructure code necessary to build an appropriate WebHostBuilder which is then used to create a TestServer by generating the HttpMessageHandler for the HttpClient used internally.

    0 讨论(0)
提交回复
热议问题