public void DeleteAccount_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var acc1 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId"); var acc2 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId2"); var acc3 = TokenCacheHelper.CreateAccountItem("tenant2", "homeAccountId"); // Assert: Delete on empty collection doesn't throw accessor.DeleteAccount(acc1); accessor.SaveAccount(acc1); accessor.SaveAccount(acc2); accessor.SaveAccount(acc3); Assert.AreEqual(3, accessor.GetAllAccounts().Count); // Assert: Delete on existing item accessor.DeleteAccount(acc1); Assert.AreEqual(2, accessor.GetAllAccounts().Count); }
public void GetAllAccounts_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var acc1 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId"); var acc2 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId2"); var acc3 = TokenCacheHelper.CreateAccountItem("tenant2", "homeAccountId"); string partitionKey1 = CacheKeyFactory.GetKeyFromCachedItem(acc1); string partitionKey2 = CacheKeyFactory.GetKeyFromCachedItem(acc2); // Assert: Returns empty collection Assert.AreEqual(0, accessor.GetAllAccounts().Count); Assert.AreEqual(0, accessor.GetAllAccounts(partitionKey1).Count); accessor.SaveAccount(acc1); accessor.SaveAccount(acc2); accessor.SaveAccount(acc3); // Assert: Get all tokens and get all tokens by partition key Assert.AreEqual(3, accessor.GetAllAccounts().Count); Assert.AreEqual(2, accessor.GetAllAccounts(partitionKey1).Count); Assert.AreEqual(1, accessor.GetAllAccounts(partitionKey2).Count); }
public void SaveAccount_Test() { var accessor = new InMemoryPartitionedUserTokenCacheAccessor(new NullLogger(), null); var acc1 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId"); // Assert: Saves with new item accessor.SaveAccount(acc1); Assert.AreEqual(1, accessor.GetAllAccounts().Count); Assert.AreEqual(1, accessor.AccountCacheDictionary.Count); string partitionKey1 = CacheKeyFactory.GetKeyFromCachedItem(acc1); Assert.IsNotNull(accessor.AccountCacheDictionary[partitionKey1][acc1.GetKey().ToString()]); var acc2 = TokenCacheHelper.CreateAccountItem("tenant2", "homeAccountId"); // Assert: Save under the existing partition accessor.SaveAccount(acc2); Assert.AreEqual(2, accessor.GetAllAccounts().Count); Assert.AreEqual(1, accessor.AccountCacheDictionary.Count); Assert.IsNotNull(accessor.AccountCacheDictionary[partitionKey1][acc2.GetKey().ToString()]); var acc3 = TokenCacheHelper.CreateAccountItem("tenant1", "homeAccountId2"); // Assert: Save under a new partition accessor.SaveAccount(acc3); // Assert: Save overwrites the existing token accessor.SaveAccount(acc3); Assert.AreEqual(3, accessor.GetAllAccounts().Count); Assert.AreEqual(2, accessor.AccountCacheDictionary.Count); string partitionKey2 = CacheKeyFactory.GetKeyFromCachedItem(acc3); Assert.IsNotNull(accessor.AccountCacheDictionary[partitionKey2][acc3.GetKey().ToString()]); }