Example #1
0
        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));
        }
Example #2
0
        public static void TestOrderedGuidCache_ItemsWithPrefix_DoesntFindUnknown()
        {
            var cache = new OrderedGuidCache();

            cache.TryAdd(Guid.Parse("67bdbe4a-1f93-4316-8c32-ae7a168a00e4"), 1);
            cache.TryAdd(Guid.Parse("fcf84364-5fbd-4866-b8a7-35b93a20dbc6"), 2);
            cache.TryAdd(Guid.Parse("06fd2e96-4c5e-4e87-918a-f217064330ea"), 3);
            Assert.IsEmpty(cache.ItemsWithPrefix("123"));
        }
Example #3
0
        public static void TestOrderedGuidCache_ItemsWithPrefix_FindsSingularKnown()
        {
            var cache = new OrderedGuidCache();
            var guid  = Guid.Parse("fcf84364-5fbd-4866-b8a7-35b93a20dbc6");

            cache.TryAdd(guid, 1);
            cache.TryAdd(Guid.Parse("67bdbe4a-1f93-4316-8c32-ae7a168a00e4"), 2);
            cache.TryAdd(Guid.Parse("06fd2e96-4c5e-4e87-918a-f217064330ea"), 3);

            var result = cache.ItemsWithPrefix(guid.ToString("N").Substring(0, 3));

            Assert.AreEqual(1, result.Count());
            Assert.That(result, Contains.Item(guid));
        }