C# unit test for ManagementApiClient

Hi There,

Currently i am using “ManagementApiClient” from the SDK Auth0.ManagementApi, Version=
I am looking for an option to mock this class as part of my implementation but i couldn’t find any interface to mock it?

Is it possible to write the unit test the class which is having “ManagementApiClient” as dependency?

If yes, can you provide some samples?


Best Regards,
Auth0 Team

1 Like

I would change the approach a little bit. The main idea is to remove dependency from your app on “ManagementApiClient”. That coupling already creates problems for you.
Here is an example of what I would do:

  1. Create interface in your app for functionality you need from “ManagementApiClient”. For example “IMyAppManagementApiClient”.
  2. Implement that interface with new class which will wrap ManagementApiClient from Auth0 library.
  3. Refactor instantiation and usage of ManagementApiClient. At that point everything should work the same way as before.
  4. Create new Implementation of “IMyAppManagementApiClient” with MockManagementApiClient. in that new implementation you will be able to mock all properties.
  5. Make a condition when you need create production instance of ManagementApiClient or mock instance for testing.
1 Like

Thanks a lot @skalinkin for sharing that approach!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.