public void DeleteIdToken_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var idt1 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId"); var idt2 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId2"); var idt3 = TokenCacheHelper.CreateIdTokenCacheItem("tenant2", "homeAccountId"); // Assert: Delete on empty collection doesn't throw accessor.DeleteIdToken(idt1); accessor.SaveIdToken(idt1); accessor.SaveIdToken(idt2); accessor.SaveIdToken(idt3); Assert.AreEqual(3, accessor.GetAllIdTokens().Count); // Assert: Delete on existing item accessor.DeleteIdToken(idt1); Assert.AreEqual(2, accessor.GetAllIdTokens().Count); }
public void GetAllIdTokens_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var idt1 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId"); var idt2 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId2"); var idt3 = TokenCacheHelper.CreateIdTokenCacheItem("tenant2", "homeAccountId"); string partitionKey1 = CacheKeyFactory.GetKeyFromCachedItem(idt1); string partitionKey2 = CacheKeyFactory.GetKeyFromCachedItem(idt2); // Assert: Returns empty collection Assert.AreEqual(0, accessor.GetAllIdTokens().Count); Assert.AreEqual(0, accessor.GetAllIdTokens(partitionKey1).Count); accessor.SaveIdToken(idt1); accessor.SaveIdToken(idt2); accessor.SaveIdToken(idt3); // Assert: Get all tokens and get all tokens by partition key Assert.AreEqual(3, accessor.GetAllIdTokens().Count); Assert.AreEqual(2, accessor.GetAllIdTokens(partitionKey1).Count); Assert.AreEqual(1, accessor.GetAllIdTokens(partitionKey2).Count); }
public void SaveIdToken_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var idt1 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId"); // Assert: Saves with new item accessor.SaveIdToken(idt1); Assert.AreEqual(1, accessor.GetAllIdTokens().Count); Assert.AreEqual(1, accessor.IdTokenCacheDictionary.Count); string partitionKey1 = CacheKeyFactory.GetKeyFromCachedItem(idt1); Assert.IsNotNull(accessor.IdTokenCacheDictionary[partitionKey1][idt1.GetKey().ToString()]); var idt2 = TokenCacheHelper.CreateIdTokenCacheItem("tenant2", "homeAccountId"); // Assert: Save under the existing partition accessor.SaveIdToken(idt2); Assert.AreEqual(2, accessor.GetAllIdTokens().Count); Assert.AreEqual(1, accessor.IdTokenCacheDictionary.Count); Assert.IsNotNull(accessor.IdTokenCacheDictionary[partitionKey1][idt2.GetKey().ToString()]); var idt3 = TokenCacheHelper.CreateIdTokenCacheItem("tenant1", "homeAccountId2"); // Assert: Save under a new partition accessor.SaveIdToken(idt3); // Assert: Save overwrites the existing token accessor.SaveIdToken(idt3); Assert.AreEqual(3, accessor.GetAllIdTokens().Count); Assert.AreEqual(2, accessor.IdTokenCacheDictionary.Count); string partitionKey2 = CacheKeyFactory.GetKeyFromCachedItem(idt3); Assert.IsNotNull(accessor.IdTokenCacheDictionary[partitionKey2][idt3.GetKey().ToString()]); }