public void DisposeWorksAsExpected()
 {
     // --- Act
     // ReSharper disable once UnusedVariable
     using (var cache = new TimeConstrainedCache <int, string>())
     {
     }
 }
 public void DisposeWorksAsExpected()
 {
     // --- Act
     // ReSharper disable once UnusedVariable
     using (var cache = new TimeConstrainedCache<int, string>())
     {
     }
 }
        public void ConstructorWithExpirationTimeSpanWorksAsExpected()
        {
            // --- Act
            var cache = new TimeConstrainedCache<int, string>(TimeSpan.FromMilliseconds(123));

            // --- Assert
            cache.Count.ShouldEqual(0);
            cache.ExpirationTimeSpan.ShouldEqual(TimeSpan.FromMilliseconds(123));
        }
        public void ConstructorWithExpirationTimeSpanWorksAsExpected()
        {
            // --- Act
            var cache = new TimeConstrainedCache <int, string>(TimeSpan.FromMilliseconds(123));

            // --- Assert
            cache.Count.ShouldEqual(0);
            cache.ExpirationTimeSpan.ShouldEqual(TimeSpan.FromMilliseconds(123));
        }
        public void GetValueFailsWithNonExistingItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            cache.GetValue(3);
        }
        public void GetValueFailsWithExpiredItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>(TimeSpan.FromMilliseconds(100));
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");
            Thread.Sleep(200);

            // --- Act
            cache.GetValue(2);
        }
        public void GetValueFailsWithExpiredItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>(TimeSpan.FromMilliseconds(100));

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");
            Thread.Sleep(200);

            // --- Act
            cache.GetValue(2);
        }
        public void ResetWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            // --- Act
            cache.ResetTo(TimeSpan.FromSeconds(15));

            // --- Assert
            cache.Count.ShouldEqual(0);
            cache.ExpirationTimeSpan.ShouldEqual(TimeSpan.FromSeconds(15));
        }
        public void ClearWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            cache.Clear();

            // --- Assert
            cache.Count.ShouldEqual(0);
        }
        public void ClearWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            cache.Clear();

            // --- Assert
            cache.Count.ShouldEqual(0);
        }
        public void GetValueWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            var value = cache.GetValue(2);

            // --- Assert
            value.ShouldEqual("two");
        }
        public void TryGetValueRecognizesNonExistingItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            string value;
            var    found = cache.TryGetValue(3, out value);

            // --- Assert
            found.ShouldBeFalse();
        }
        public void TryGetValueWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            string value;
            var    found = cache.TryGetValue(2, out value);

            // --- Assert
            found.ShouldBeTrue();
            value.ShouldEqual("two");
        }
        public void TryGetValueRecognizesWithExpiredItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>(TimeSpan.FromMilliseconds(100));

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");
            Thread.Sleep(200);

            // --- Act
            string value;
            var    found = cache.TryGetValue(2, out value);

            // --- Assert
            found.ShouldBeFalse();
        }
        public void ContainsWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            var contains1 = cache.Contains(1);
            var contains2 = cache.Contains(2);
            var contains3 = cache.Contains(3);

            // --- Assert
            contains1.ShouldBeTrue();
            contains2.ShouldBeTrue();
            contains3.ShouldBeFalse();
        }
        public void ContainsWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache <int, string>();

            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            var contains1 = cache.Contains(1);
            var contains2 = cache.Contains(2);
            var contains3 = cache.Contains(3);

            // --- Assert
            contains1.ShouldBeTrue();
            contains2.ShouldBeTrue();
            contains3.ShouldBeFalse();
        }
        public void TryGetValueWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            string value;
            var found = cache.TryGetValue(2, out value);

            // --- Assert
            found.ShouldBeTrue();
            value.ShouldEqual("two");
        }
        public void TryGetValueRecognizesWithExpiredItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>(TimeSpan.FromMilliseconds(100));
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");
            Thread.Sleep(200);

            // --- Act
            string value;
            var found = cache.TryGetValue(2, out value);

            // --- Assert
            found.ShouldBeFalse();
        }
        public void TryGetValueRecognizesNonExistingItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            string value;
            var found = cache.TryGetValue(3, out value);

            // --- Assert
            found.ShouldBeFalse();
        }
        public void ResetWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();

            // --- Act
            cache.ResetTo(TimeSpan.FromSeconds(15));

            // --- Assert
            cache.Count.ShouldEqual(0);
            cache.ExpirationTimeSpan.ShouldEqual(TimeSpan.FromSeconds(15));
        }
        public void GetValueFailsWithNonExistingItem()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            cache.GetValue(3);
        }
        public void RemoveWorksAsExpected()
        {
            // --- Arrange
            var cache = new TimeConstrainedCache<int, string>();
            cache.SetValue(1, "one");
            cache.SetValue(2, "two");

            // --- Act
            var value = cache.GetValue(2);
            cache.Remove(2);

            // --- Assert
            value.ShouldEqual("two");
            cache.Contains(2).ShouldBeFalse();
        }