public static void TestOrderedGuidCache_Remove_LeavesMostRecentlyAccessedItems() { var cache = new OrderedGuidCache(); var guidRemoved1 = Guid.NewGuid(); var guidRemoved2 = Guid.NewGuid(); var guidStays1 = Guid.NewGuid(); var guidStays2 = Guid.NewGuid(); var guidStays3 = Guid.NewGuid(); cache.TryAdd(guidStays1, 2); Thread.Sleep(100); cache.TryAdd(guidStays2, 2); Thread.Sleep(100); cache.TryAdd(guidRemoved1, 2); Thread.Sleep(100); cache.TryAdd(guidRemoved2, 2); Thread.Sleep(100); cache.TryAdd(guidStays3, 2); Thread.Sleep(100); // Touch the timestamps cache.Contains(guidStays1); Thread.Sleep(100); cache.Contains(guidStays3); Thread.Sleep(100); cache.ItemsWithPrefix(guidStays2.ToString("N").Substring(0, 3)); Thread.Sleep(100); cache.Remove(3, out var sizeCleared); Assert.True(cache.Contains(guidStays1)); Assert.True(cache.Contains(guidStays2)); Assert.True(cache.Contains(guidStays3)); }
public static void TestOrderedGuidCache_Remove_Empty_ReturnsEmptyAndZero() { var cache = new OrderedGuidCache(); var removed = cache.Remove(100, out var sizeCleared); Assert.IsEmpty(removed); Assert.AreEqual(0, sizeCleared); }
public static void TestOrderedGuidCache_Remove_ReportsCorrectSizeCleared() { var cache = new OrderedGuidCache(); cache.TryAdd(Guid.NewGuid(), 2); cache.TryAdd(Guid.NewGuid(), 4); cache.TryAdd(Guid.NewGuid(), 8); cache.Remove(5, out var sizeCleared); Assert.AreEqual(6, sizeCleared); }
public static void TestOrderedGuidCache_Remove_RemovesItems() { var cache = new OrderedGuidCache(); cache.TryAdd(Guid.NewGuid(), 2); cache.TryAdd(Guid.NewGuid(), 4); cache.TryAdd(Guid.NewGuid(), 8); cache.Remove(5, out var sizeCleared); Assert.Less(cache.Count, 3); }