Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sw-joelmut committed Sep 19, 2023
1 parent 68f252f commit b158a9c
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace Microsoft.Bot.Connector.Tests.Authentication
{
public class ManagedIdentityAuthenticatorTests
{
private const string TestAppId = "foo";
private const string TestAudience = "bar";
private readonly Func<string, string> appId = (id) => $"id {id} ";
private readonly Func<string, string> audience = (id) => $"audience {id} ";

[Fact]
public void CanGetJwtToken()
Expand All @@ -37,17 +37,17 @@ public void CanGetJwtToken()
.ReturnsAsync(response);
var httpClient = new HttpClient(mockHttpMessageHandler.Object);

var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient);
var sut = new ManagedIdentityAuthenticator(appId(nameof(CanGetJwtToken)), audience(nameof(CanGetJwtToken)), httpClient);
var token = sut.GetTokenAsync().GetAwaiter().GetResult();

Assert.Equal("at_secret", token.AccessToken);
Assert.Equal(expiresOn, token.ExpiresOn.ToUnixTimeSeconds());
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput)
[InlineData(false, 1)]
[InlineData(true, 2)]
public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput, int index)
{
var response = new HttpResponseMessage(HttpStatusCode.OK);
var expiresOn = DateTimeOffset.Now.ToUnixTimeSeconds() + 10000;
Expand All @@ -64,7 +64,7 @@ public void CanGetJwtTokenWithForceRefresh(bool forceRefreshInput)
.ReturnsAsync(response);
var httpClient = new HttpClient(mockHttpMessageHandler.Object);

var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient);
var sut = new ManagedIdentityAuthenticator(appId(nameof(CanGetJwtTokenWithForceRefresh)) + index, audience(nameof(CanGetJwtTokenWithForceRefresh)) + index, httpClient);
var token = sut.GetTokenAsync(forceRefreshInput).GetAwaiter().GetResult();

Assert.Equal("at_secret", token.AccessToken);
Expand All @@ -86,7 +86,7 @@ public void DefaultRetryOnException()
});
var httpClient = new HttpClient(mockHttpMessageHandler.Object);

var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient);
var sut = new ManagedIdentityAuthenticator(appId(nameof(DefaultRetryOnException)), audience(nameof(DefaultRetryOnException)), httpClient);

try
{
Expand Down Expand Up @@ -130,7 +130,7 @@ public void CanRetryAndAcquireToken()
});
var httpClient = new HttpClient(mockHttpMessageHandler.Object);

var sut = new ManagedIdentityAuthenticator(TestAppId, TestAudience, httpClient);
var sut = new ManagedIdentityAuthenticator(appId(nameof(CanRetryAndAcquireToken)), audience(nameof(CanRetryAndAcquireToken)), httpClient);
var token = sut.GetTokenAsync().GetAwaiter().GetResult();

Assert.Equal("at_secret", token.AccessToken);
Expand Down

0 comments on commit b158a9c

Please sign in to comment.