Пример #1
0
        public void GetOrAdd_AddsIfKeyDoesNotExist()
        {
            // Arrange
            var input    = GetKeyValueArray(Enumerable.Range(1, 3));
            var expected = GetKeyValueArray(Enumerable.Range(2, 3)).Reverse();
            var cache    = new ConcurrentLruCache <int, int>(input);

            // Act
            cache.GetOrAdd(4, 4);

            // Assert
            Assert.Equal(expected, cache.TestingEnumerable);
        }
Пример #2
0
        public void Add_ReadLastNode_EvictsSecondOldestNode()
        {
            // Arrange
            var input    = GetKeyValueArray(Enumerable.Range(1, 3));
            var expected = GetKeyValueArray(new int[] { 4, 1, 3 });
            var cache    = new ConcurrentLruCache <int, int>(input);

            // Act
            cache.GetOrAdd(1, 1); // Read to make this MRU
            cache.Add(4, 4);      // Add a new node

            // Assert
            Assert.Equal(expected, cache.TestingEnumerable);
        }