コード例 #1
0
        public void MsalDistributedTokenCacheAdapterOptions_DisableL1Cache(bool disableL1Cache)
        {
            // Arrange
            var msalDistributedTokenOptions = Options.Create(
                new MsalDistributedTokenCacheAdapterOptions()
            {
                DisableL1Cache = disableL1Cache,
            });

            BuildTheRequiredServices();

            // Act
            var testCache = new TestMsalDistributedTokenCacheAdapter(
                new TestDistributedCache(),
                msalDistributedTokenOptions,
                _provider.GetService <ILogger <MsalDistributedTokenCacheAdapter> >());

            // Assert
            Assert.NotNull(testCache);
            Assert.NotNull(testCache._distributedCache);

            if (!disableL1Cache)
            {
                Assert.NotNull(testCache._memoryCache);
                Assert.Equal(0, testCache._memoryCache.Count);
            }
            else
            {
                Assert.Null(testCache._memoryCache);
            }
        }
コード例 #2
0
 public L1L2CacheTests()
 {
     BuildTheRequiredServices();
     _testCacheAdapter = new TestMsalDistributedTokenCacheAdapter(
         MakeMockDistributedCache(),
         _provider.GetService <IOptions <MsalDistributedTokenCacheAdapterOptions> >(),
         _provider.GetService <ILogger <MsalDistributedTokenCacheAdapter> >());
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void MsalDistributedTokenCacheAdapterOptions_L1ExpirationTimeRatio(double expirationRatio)
        {
            // Arrange
            var msalDistributedTokenOptions = Options.Create(
                new MsalDistributedTokenCacheAdapterOptions()
            {
                L1ExpirationTimeRatio           = expirationRatio,
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3),
            });

            BuildTheRequiredServices();

            // Act
            var testCache = new TestMsalDistributedTokenCacheAdapter(
                new TestDistributedCache(),
                msalDistributedTokenOptions,
                _provider.GetService <ILogger <MsalDistributedTokenCacheAdapter> >());

            // Assert
            Assert.NotNull(testCache);
            Assert.NotNull(testCache._distributedCache);
            Assert.NotNull(testCache._memoryCache);
            Assert.Equal(0, testCache._memoryCache.Count);
        }
コード例 #5
0
 private static void AssertCacheValues(TestMsalDistributedTokenCacheAdapter testCache)
 {
     Assert.NotNull(testCache);
     Assert.NotNull(testCache._distributedCache);
     Assert.NotNull(testCache._memoryCache);
 }