Repository: AzureAD/microsoft-authentication-library-for-dotnet

Issue #1702: [Bug] IPublicClientApplication is not mockable
Created: 2020-03-12T21:00:27Z
Which Version of MSAL are you using ?
Latest
Platform
Any
What authentication flow has the issue?
N/A
Is this a new or existing app?
N/A
Repro
IPublicClientApplication is not mockable. Specifically the AcquireTokenByIntegratedWindowsAuth method returns a AcquireTokenByIntegratedWindowsAuthParameterBuilder object, but that class only has internal constructors. This makes any class using that method untestable.
Expected behavior
IPublicClientApplication is mockble
Actual behavior
IPublicClientApplication is not mockable
Possible Solution
Either make the return values constructable, or interface them out.
Additional context/ Logs / Screenshots
N/A

Duplicate issue #2449: [Feature Request] Cannot unit test code that uses IConfidentialClientApplication because AcquireTokenForClient() returns AcquireTokenForClientParameterBuilder which cannot be mocked
Created: 2021-03-03T19:30:46Z
Is your feature request related to a problem? Please describe.
I am writing code that utilizes IConfidentialClientApplication to obtain access tokens. The following is a simplified version of my code...
First I have a method on my class to get an access token:
        public async Task<string> GetAuthorizationToken(IEnumerable<string> scopes)
        {
                AcquireTokenForClientParameterBuilder acquireToken = _client.AcquireTokenForClient(scopes);
                AuthenticationResult authResult = await acquireToken.ExecuteAsync();

                return authResult.AccessToken;
        }
The _client object in that method is passed to my class via a constructor so I can use Dependency Injection or just provide a new instance myself for testing:
        private readonly IConfidentialClientApplication _client;
        
        public ClientCredentialsJwtClient(IConfidentialClientApplication client)
        {
            _client = client;
        }
In my unit test code, I make a new mocked instance of IConfidentialClientApplication using Moq like this:
        Mock<IConfidentialClientApplication> client = new Mock<IConfidentialClientApplication>();
This allows me to stub out the call to _client.AcquireTokenForClient(scopes) in my code above but now the problem is that method returns an AcquireTokenForClientParameterBuilder object and this is a sealed class with no constructor. So I can't make a test instance of it and I cannot mock it either.
Describe the solution you'd like
I may be missing an approach that would get around this but it seems to me that I'm stuck here. It would be very beneficial to make _client.AcquireTokenForClient(scopes) return something like an IAcquireTokenForClientParameterBuilder so I can then mock that object as well.
Describe alternatives you've considered
I suppose I could add another layer of abstraction around the use of IConfidentialClientApplication but that means I won't be able to unit test that code (though I could unit test the code using it).
Additional context
None

Closing comment (2022-10-19T19:05:04Z): Duplicate of #1702, which we won't fixed. @bgavrilMS : I let you comment in the same way ?

Either this isn't a duplicate, or the reason #1702 is closed doesn't seem valid. Why not just unseal AcquireTokenForClientParameterBuilder?
If it was unsealed, it could be mocked. I don't see how simply unsealing a class could be considered major modifications to major APIs.