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()); } }