Пример #1
0
        public void Get_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("Get_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.Get <string>("Get_NotExists");

            // Assert
            actual.ShouldHaveSameValueAs(null);
        }
Пример #2
0
        public void Delete_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("Delete_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.Delete("Delete_NotExists");

            // Assert
            MemoryCache.Default.Contains("Delete_NotExists").ShouldHaveSameValueAs(false);
        }
Пример #3
0
        public void Get_Exists()
        {
            // Arrange
            MemoryCache.Default.Add("Get_Exists", "some value", new CacheItemPolicy());
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.Get <string>("Get_Exists");

            // Assert
            actual.ShouldHaveSameValueAs("some value");
        }
Пример #4
0
        public void AddSlidingExpiration_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("AddSlidingExpiration_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.AddSlidingExpiration("AddSlidingExpiration_NotExists", "value2", TimeSpan.FromMinutes(1));

            // Assert
            MemoryCache.Default.Get("AddSlidingExpiration_NotExists").ShouldHaveSameValueAs("value2");
        }
Пример #5
0
        public void Delete_Exists()
        {
            // Arrange
            MemoryCache.Default.Add("Delete_Exists", "some value", new CacheItemPolicy());
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.Delete("Delete_Exists");

            // Assert
            MemoryCache.Default.Contains("Delete_Exists").ShouldHaveSameValueAs(false);
        }
Пример #6
0
        public void AddExactExpiration_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("AddExactExpiration_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.AddExactExpiration("AddExactExpiration_NotExists", "value2", ApplicationContext.NetworkContext.CurrentDateTime.AddSeconds(2));

            // Assert
            MemoryCache.Default.Get("AddExactExpiration_NotExists").ShouldHaveSameValueAs("value2");
        }
Пример #7
0
        public void ContainsKey_False()
        {
            // Arrange
            MemoryCache.Default.Remove("ContainsKey_False");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.ContainsKey("ContainsKey_False");

            // Assert
            actual.ShouldHaveSameValueAs(false);
        }
Пример #8
0
        public void Add_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("Add_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.Add("Add_NotExists", "value2");

            // Assert
            MemoryCache.Default.Get("Add_NotExists").ShouldHaveSameValueAs("value2");
        }
Пример #9
0
        public void ContainsKey_True()
        {
            // Arrange
            MemoryCache.Default.Add("ContainsKey_True", "test value", new CacheItemPolicy());
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.ContainsKey("ContainsKey_True");

            // Assert
            actual.ShouldHaveSameValueAs(true);
        }
Пример #10
0
        public void GetOrAddAndGetExactExpiration_Exists()
        {
            // Arrange
            MemoryCache.Default.Add("GetOrAddAndGetExactExpiration_Exists", "value1", new CacheItemPolicy());
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.GetOrAddAndGetExactExpiration("GetOrAddAndGetExactExpiration_Exists", ApplicationContext.NetworkContext.CurrentDateTime.AddSeconds(2), () => "value2");

            // Assert
            actual.ShouldHaveSameValueAs("value1");
            MemoryCache.Default.Get("GetOrAddAndGetExactExpiration_Exists").ShouldHaveSameValueAs("value1");
        }
Пример #11
0
        public void GetOrAddAndGetSlidingExpiration_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("GetOrAddAndGetSlidingExpiration_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.GetOrAddAndGetSlidingExpiration("GetOrAddAndGetSlidingExpiration_NotExists", TimeSpan.FromMinutes(1), () => "value2");

            // Assert
            actual.ShouldHaveSameValueAs("value2");
            MemoryCache.Default.Get("GetOrAddAndGetSlidingExpiration_NotExists").ShouldHaveSameValueAs("value2");
        }
Пример #12
0
        public void GetOrAddAndGet_NotExists()
        {
            // Arrange
            MemoryCache.Default.Remove("GetOrAddAndGet_NotExists");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.GetOrAddAndGet("GetOrAddAndGet_NotExists", () => "value2");

            // Assert
            actual.ShouldHaveSameValueAs("value2");
            MemoryCache.Default.Get("GetOrAddAndGet_NotExists").ShouldHaveSameValueAs("value2");
        }
Пример #13
0
        public void AddSlidingExpiration_NotExists_Timeout()
        {
            // Arrange
            MemoryCache.Default.Remove("AddSlidingExpiration_NotExists_Timeout");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.AddSlidingExpiration("AddSlidingExpiration_NotExists_Timeout", "value2", TimeSpan.FromSeconds(2));

            // Assert
            MemoryCache.Default.Get("AddSlidingExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2");

            Thread.Sleep(2100);
            componentUnderTest.Get <string>("AddSlidingExpiration_NotExists_Timeout").ShouldHaveSameValueAs(null);
        }
Пример #14
0
        public void AddExactExpiration_NotExists_Timeout()
        {
            // Arrange
            MemoryCache.Default.Remove("AddExactExpiration_NotExists_Timeout");
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.AddExactExpiration("AddExactExpiration_NotExists_Timeout", "value2", ApplicationContext.NetworkContext.CurrentDateTime.AddSeconds(2));

            // Assert
            MemoryCache.Default.Get("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2");

            for (var i = 0; i < 3; i++)
            {
                Thread.Sleep(500);
                componentUnderTest.Get <string>("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs("value2");
            }
            Thread.Sleep(500);
            componentUnderTest.Get <string>("AddExactExpiration_NotExists_Timeout").ShouldHaveSameValueAs(null);
        }
Пример #15
0
        public void AddSlidingExpiration_NotExists_RenewAndThenTimeout()
        {
            // Arrange
            const string key = "AddSlidingExpiration_NotExists_RenewAndThenTimeout";

            MemoryCache.Default.Remove(key);
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            componentUnderTest.AddSlidingExpiration(key, "value2", TimeSpan.FromSeconds(2));

            // Assert
            componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2");

            for (var i = 0; i < 5; i++)
            {
                Thread.Sleep(500);
                componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2");
            }
            Thread.Sleep(2100);
            componentUnderTest.Get <string>(key).ShouldHaveSameValueAs(null);
        }
Пример #16
0
        public void GetOrAddAndGetSlidingExpiration_NotExists_RenewAndThenTimeout()
        {
            // Arrange
            const string key = "GetOrAddAndGetSlidingExpiration_NotExists_RenewAndThenTimeout";

            MemoryCache.Default.Remove(key);
            var componentUnderTest = new MemoryCacheAdapter();

            // Act
            var actual = componentUnderTest.GetOrAddAndGetSlidingExpiration(key, TimeSpan.FromSeconds(2), () => "value2");

            // Assert
            actual.ShouldHaveSameValueAs("value2");
            MemoryCache.Default.Get(key).ShouldHaveSameValueAs("value2");

            for (int i = 0; i < 3; i++)
            {
                Thread.Sleep(1000);
                componentUnderTest.Get <string>(key).ShouldHaveSameValueAs("value2");
            }
            Thread.Sleep(2100);
            componentUnderTest.Get <string>(key).ShouldHaveSameValueAs(null);
        }