Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Mocking ADAL for Unit Tests
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