How to mock/create X509Certificate2 for unit testing?

14,056

As Steve suggested, I created my own certificate on the run. I utilised method from this ticket. Certificate is fully functional for purpose of testing.

Share:
14,056
Qerts
Author by

Qerts

Updated on July 20, 2022

Comments

  • Qerts
    Qerts almost 2 years

    I have handler which creates jwt token with utilization of X509Certificate2. For unit test I need to provide certificate and it is not possible for me take it from the local store. Is there way, how to mock, create or load certificate from the file?

    So far I tried BouncingCastle method from this ticket, but with no success. The method ToX509Certificate2() does convert certificate, but without keys. So if this is good way to go, is possible to generate these keys somehow?

    Thanks a lot for hints