Integration testing with in-memory IdentityServer

前端 未结 7 1585
一生所求
一生所求 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:26

    I understand there is a need for a more complete answer than what @james-fera posted. I have learned from his answer and made a github project consisting of a test project and API project. The code should be self-explanatory and not hard to understand.

    https://github.com/emedbo/identityserver-test-template

    The IdentityServerSetup.cs class https://github.com/emedbo/identityserver-test-template/blob/master/tests/API.Tests/Config/IdentityServerSetup.cs can be abstracted away e.g. NuGetted away, leaving the base class IntegrationTestBase.cs

    The essences is that can make the test IdentityServer work just like a normal IdentityServer, with users, clients, scopes, passwords etc. I have made the DELETE method [Authorize(Role="admin)] to prove this.

    Instead of posting code here, I recommend read @james-fera's post to get the basics then pull my project and run tests.

    IdentityServer is such a great tool, and with the ability to use the TestServer framework it gets even better.

提交回复
热议问题