public async Task CommunicationTokenCredential_StaticToken_ReturnsExpiredToken(bool async) { using var tokenCredential = new CommunicationTokenCredential(ExpiredToken); var token = async ? await tokenCredential.GetTokenAsync() : tokenCredential.GetToken(); Assert.AreEqual(ExpiredToken, token.Token); }
public void GetTokenSeries_StaticToken_Throws_IfTokenRequestedWhileDisposed(bool async) { using var tokenCredential = new CommunicationTokenCredential(SampleToken); tokenCredential.Dispose(); if (async) { Assert.ThrowsAsync <ObjectDisposedException>(async() => await tokenCredential.GetTokenAsync()); } else { Assert.Throws <ObjectDisposedException>(() => tokenCredential.GetToken()); } }
public void GetTokenSeries_Throws_IfTokenRequestedWhileDisposed(string token, bool refreshProactively, bool async) { using var tokenCredential = new CommunicationTokenCredential( new CommunicationTokenRefreshOptions( refreshProactively, _ => token) { AsyncTokenRefresher = _ => new ValueTask <string>(token) }); tokenCredential.Dispose(); if (async) { Assert.ThrowsAsync <ObjectDisposedException>(async() => await tokenCredential.GetTokenAsync()); } else { Assert.Throws <ObjectDisposedException>(() => tokenCredential.GetToken()); } }
public async Task CommunicationTokenCredential_PassesCancellationToken(bool refreshProactively, bool async) { var cancellationToken = new CancellationToken(); CancellationToken?actualCancellationToken = null; using var tokenCredential = new CommunicationTokenCredential( new CommunicationTokenRefreshOptions( refreshProactively, RefreshToken) { AsyncTokenRefresher = c => new ValueTask <string>(RefreshToken(c)), InitialToken = ExpiredToken }); var token = async ? await tokenCredential.GetTokenAsync(cancellationToken) : tokenCredential.GetToken(cancellationToken); Assert.AreEqual(cancellationToken, actualCancellationToken); string RefreshToken(CancellationToken token) { actualCancellationToken = token; return(SampleToken); } }