public async Task WhenExpiredTokenInCache_AcquiresNew() { // Arrange. var token0 = MockAccessTokenCache.CreateMockAccessToken("expired", DateTimeOffset.Now); var token1 = MockAccessTokenCache.CreateValidAccessToken(); var tokenCache = new MockAccessTokenCache(initialValue: token0, mockTokens: token1); // Act. var result = await tokenCache.GetAsync( MockConnectionString, MockAccessTokenCache.DefaultCertificateData); // Assert. Assert.Equal(1, tokenCache.AcquireTokenCount); Assert.Equal("valid", result.AccessToken); }
public async Task WhenNearExpiredTokenInCache_AcquiresNewInBackground() { // Arrange. var token0 = MockAccessTokenCache.CreateMockAccessToken("nearExpired", DateTimeOffset.Now + TimeSpan.FromMinutes(10)); var token1 = MockAccessTokenCache.CreateValidAccessToken(); var tokenCache = new MockAccessTokenCache(initialValue: token0, mockTokens: token1); // Act. var result = await tokenCache.GetAsync( MockConnectionString, MockAccessTokenCache.DefaultCertificateData); // Assert. Assert.Equal("nearExpired", result.AccessToken); await Task.Delay(500); Assert.Equal(1, tokenCache.AcquireTokenCount); }