예제 #1
0
        public void Add_ThrowsIfKeyExists()
        {
            // Arrange
            var input = GetKeyValueArray(Enumerable.Range(1, 3));
            var cache = new ConcurrentLruCache <int, int>(input);

            // Act & Assert
            var exception = Assert.Throws <ArgumentException>(() => cache.Add(1, 1));

            Assert.StartsWith("Key already exists", exception.Message);
        }
예제 #2
0
        public void Add_NoRead_EvictsLastNode()
        {
            // 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.Add(4, 4);

            // Assert
            Assert.Equal(expected, cache.TestingEnumerable);
        }
예제 #3
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);
        }