public async Task EncryptionTestAsync(bool isEncrypted) { // Arrange byte[] cache = new byte[] { 1, 2, 3, 4 }; BuildTheRequiredServices(isEncrypted); _testCacheAdapter = _provider.GetService <IMsalTokenCacheProvider>() as TestMsalDistributedTokenCacheAdapter; TestTokenCache tokenCache = new TestTokenCache(); TokenCacheNotificationArgs args = InstantiateTokenCacheNotificationArgs(tokenCache); _testCacheAdapter.Initialize(tokenCache); // Act await tokenCache._beforeAccess(args).ConfigureAwait(false); tokenCache.cache = cache; await tokenCache._afterAccess(args).ConfigureAwait(false); // Assert Assert.Equal(1, _testCacheAdapter._memoryCache.Count); Assert.NotEqual(cache.SequenceEqual(GetFirstCacheValue()), isEncrypted); }
private static TokenCacheNotificationArgs InstantiateTokenCacheNotificationArgs(TestTokenCache tokenCache) { ITokenCacheSerializer tokenCacheSerializer = tokenCache; string clientId = string.Empty; IAccount account = null; bool hasStateChanged = true; bool isAppCache = false; bool hasTokens = true; CancellationToken cancellationToken = CancellationToken.None; string suggestedCacheKey = "key"; DateTimeOffset? suggestedCacheExpiry = null; TokenCacheNotificationArgs args = new TokenCacheNotificationArgs( tokenCacheSerializer, clientId, account, hasStateChanged, isAppCache, suggestedCacheKey, hasTokens, suggestedCacheExpiry, cancellationToken); return(args); }