Exemple #1
0
        public void AddingNewItemGivenCacheFullShouldRemoveLru(Fixture fixture, LeastRecentlyUsedCache <int, string> sut)
        {
            // Arrange
            for (int i = 0; i < sut.Capacity; i++)
            {
                var key = fixture.Create <int>();
                sut.AddEntry(key, fixture.Create <string>());
            }

            var currentLru = sut.GetLeastRecentlyUsedEntry();
            var newKey     = fixture.Create <int>();
            var newValue   = fixture.Create <string>();

            // Act
            sut.AddEntry(newKey, newValue);
            var actual = sut.ContainsKey(currentLru.Key);

            // Assert
            actual.ShouldBeFalse();
        }
Exemple #2
0
        public void GetMostRecentlyUsedEntryReturnsValidEntry(Fixture fixture, LeastRecentlyUsedCache <int, string> sut)
        {
            // Arrange
            for (int i = 0; i < sut.Capacity; i++)
            {
                var key = fixture.Create <int>();
                sut.AddEntry(key, fixture.Create <string>());
            }

            var currentLru = sut.GetLeastRecentlyUsedEntry();

            // Act
            sut.AddEntry(currentLru.Key, currentLru.Entry);
            var actualMru = sut.GetMostRecentlyUsedEntry();
            var actualLru = sut.GetLeastRecentlyUsedEntry();

            // Assert
            actualMru.ShouldBe(currentLru);
            actualLru.ShouldNotBe(currentLru);
        }
Exemple #3
0
        public void AddEntryShouldReturnEntryUsingGetEntry(int key, string actual, LeastRecentlyUsedCache <int, string> sut)
        {
            // Arrange

            // Act
            sut.AddEntry(key, actual);
            var expected = sut.GetEntry(key);

            // Assert
            actual.ShouldBe(expected);
        }
Exemple #4
0
        public void RemoveEntryShouldRemove(int key, string entry, LeastRecentlyUsedCache <int, string> sut)
        {
            // Arrange
            sut.AddEntry(key, entry);

            // Act
            sut.RemoveEntry(key);
            var actual = sut.GetEntry(key);

            // Assert
            actual.ShouldBeNull();
        }
Exemple #5
0
        public void ClearShouldRemoveAllData(int[] keys, string[] entries, LeastRecentlyUsedCache <int, string> sut)
        {
            // Arrange
            for (int i = 0; i < keys.Length; i++)
            {
                sut.AddEntry(keys[i], entries[i]);
            }

            // Act
            sut.Clear();
            var actual = sut.Count;

            // Assert
            actual.ShouldBe(0);
        }