-
-
Save justinyoo/706ff88512255432e2ccb5697a3f3728 to your computer and use it in GitHub Desktop.
Mocking ADAL for Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AuthenticationContextWrapper : IAuthenticationContextWrapper | |
{ | |
public AuthenticationContextWrapper(AuthenticationContext context) | |
{ | |
this.Context = context; | |
} | |
public AuthenticationContextWrapper(string authority) | |
{ | |
this.Context = new AuthenticationContext(authority); | |
} | |
public AuthenticationContextWrapper(string authority, bool validateAuthority) | |
{ | |
this.Context = new AuthenticationContext(authority, validateAuthority); | |
} | |
public AuthenticationContextWrapper(string authority, bool validateAuthority, TokenCache tokenCache) | |
{ | |
this.Context = new AuthenticationContext(authority, validateAuthority, tokenCache); | |
} | |
public AuthenticationContext Context { get; } | |
public string Authority => this.Context.Authority; | |
public bool ValidateAuthority => this.Context.ValidateAuthority; | |
... | |
public async Task<IDeviceCodeResultWrapper> AcquireDeviceCodeAsync(string resource, string clientId) | |
{ | |
var result = await this.Context.AcquireDeviceCodeAsync(resource, clientId).ConfigureAwait(false); | |
return new DeviceCodeResultWrapper(result); | |
} | |
... | |
public async Task<IAuthenticationResultWrapper> AcquireTokenAsync(string resource, string clientId, UserCredential userCredential) | |
{ | |
var result = await this.Context.AcquireTokenAsync(resource, clientId, userCredential).ConfigureAwait(false); | |
return new AuthenticationResultWrapper(result); | |
} | |
... | |
public async Task<IAuthenticationResultWrapper> AcquireTokenAsync(string resource, ClientCredential clientCredential) | |
{ | |
var result = await this.Context.AcquireTokenAsync(resource, clientCredential).ConfigureAwait(false); | |
return new AuthenticationResultWrapper(result); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment