How to Mock AuthenticationApiClient & ManagementApiClient to write unit tests in .Net Core

Hi team,

I would like to unit test my service layer of .Net core 5 API which uses AuthenticationApiClient & ManagementApiClient . I have read lot of articles but didn’t find a clear explanation of how to achieve this.

I went through Auth0 .NET SDK

And also how to registed these classes in the startup file.

I have added the following line for AuthenticationApiClient.
services.AddSingleton(x =>
** new AuthenticationApiClient(new Uri($“https://{Configuration[“Auth0:Domain”]}/”)));**

Below line for IManagementConnection
services.AddSingleton<IManagementConnection, HttpClientManagementConnection>();

Using the follow line to get managementApiClient in my classses to get the instance. I am sharing the _managementConnection.

var token = await GenerateManagementApiToken();
** var managementApiClient = new ManagementApiClient(token, _configuration[“Auth0:Domain”], _managementConnection);**

I am struggling to write Unit Test cases.

Also when writing Integration test cases do we need to hit Auth0 directly?

Any guidance or a sample would be of great help.

Thanks
Sathish