public void EmptyPolicy() { var policy = new PagePrefetchAndRetainPolicy(); var key = new PageKey(Guid.Empty, 1, ScreenWidth); var context = new PageCacheContext(ScreenWidth, GetLibrary(0)); Assert.IsFalse(policy.MustRetain(key, context), "not retain with empty library"); var dict = GetCacheDict(0); CollectionAssert.IsEmpty(policy.KeysToRemove(dict, context), "no keys exist"); dict = GetCacheDict(5); CollectionAssert.AreEquivalent(dict.Keys, policy.KeysToRemove(dict, context), "return all keys"); CollectionAssert.IsEmpty(policy.PrefetchKeyOrder(context), "prefetch list empty"); }
public void Remove_KeepOtherItems() { var context = new PageCacheContext(ScreenWidth, GetLibrary(1)); var policy = new PagePrefetchAndRetainPolicy() { OtherItemsToKeepCount = 7 }; var dict = GetCacheDict(10); var keysToRemove = policy.KeysToRemove(dict, context); // Keeping 7 items, removing 3 Assert.AreEqual(3, keysToRemove.Count()); // Makes sure *oldest* ones are removed Assert.AreEqual(BaseTime + TimeSpan.FromDays(0), dict[keysToRemove.ElementAt(2)].LastAccessTime); Assert.AreEqual(BaseTime + TimeSpan.FromDays(1), dict[keysToRemove.ElementAt(1)].LastAccessTime); Assert.AreEqual(BaseTime + TimeSpan.FromDays(2), dict[keysToRemove.ElementAt(0)].LastAccessTime); // Must NOT retain those keys foreach (var key in keysToRemove) { Assert.IsFalse(policy.MustRetain(key, context)); } }