-
-
Save justinyoo/2a0fc9ab5299a0ca8c737f8372a8a392 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
using FluentAssertions; | |
using Moq; | |
using Xunit; | |
var authResult = new Mock<IAuthenticationResultWrapper>(); | |
var authContext = new Mock<IAuthenticationContextWrapper>(); | |
var wrapper = new AdalWrapper(this.AuthenticationContext.Object); | |
var resourceUrl = "http://localhost"; | |
var clientId = "CLIENT_ID"; | |
var clientSecret = "CLIENT_SECRET"; | |
var accessToken = "ACCESS_TOKEN"; | |
authResult.SetupGet(p => p.AccessToken).Returns(accessToken); | |
authContext.Setup(p => p.AcquireTokenAsync(It.IsAny<string>(), It.IsAny<ClientCredential>())).ReturnsAsync(authResult.Object); | |
var result = await wrapper.AcquireTokenAsync(resource, clientId, clientSecret).ConfigureAwait(false); | |
result.AccessToken.Should().BeEquivalentTo(accessToken); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment