Exemplo n.º 1
0
        public void UpdateCacheContext_PrefersAbsoluteExpirationSpecifiedOnEntryLinkOverExpiresOn()
        {
            // Arrange
            var expiresOn1   = DateTimeOffset.UtcNow.AddDays(12);
            var expiresOn2   = DateTimeOffset.UtcNow.AddMinutes(4);
            var cache        = new MemoryCache(new MemoryCacheOptions());
            var cacheContext = new Mock <ICacheSetContext>();
            var sequence     = new MockSequence();

            cacheContext.InSequence(sequence)
            .Setup(c => c.SetAbsoluteExpiration(expiresOn1))
            .Verifiable();

            cacheContext.InSequence(sequence)
            .Setup(c => c.SetAbsoluteExpiration(expiresOn2))
            .Verifiable();

            var cacheTagHelper = new CacheTagHelper
            {
                MemoryCache = cache,
                ExpiresOn   = expiresOn1
            };

            var entryLink = new EntryLink();

            entryLink.SetAbsoluteExpiration(expiresOn2);

            // Act
            cacheTagHelper.UpdateCacheContext(cacheContext.Object, entryLink);

            // Assert
            cacheContext.Verify();
        }
Exemplo n.º 2
0
        public void UpdateCacheEntryOptions_UsesAbsoluteExpirationSpecifiedOnEntryLink()
        {
            // Arrange
            var expiresOn      = DateTimeOffset.UtcNow.AddMinutes(7);
            var cache          = new MemoryCache(new MemoryCacheOptions());
            var cacheTagHelper = new CacheTagHelper(cache)
            {
            };

            var entryLink = new EntryLink();

            entryLink.SetAbsoluteExpiration(expiresOn);

            // Act
            var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(entryLink);

            // Assert
            Assert.Equal(expiresOn, cacheEntryOptions.AbsoluteExpiration);
        }
Exemplo n.º 3
0
        public void UpdateCacheEntryOptions_PrefersAbsoluteExpirationSpecifiedOnEntryLinkOverExpiresOn()
        {
            // Arrange
            var expiresOn1     = DateTimeOffset.UtcNow.AddDays(12);
            var expiresOn2     = DateTimeOffset.UtcNow.AddMinutes(4);
            var cache          = new MemoryCache(new MemoryCacheOptions());
            var cacheTagHelper = new CacheTagHelper(cache)
            {
                ExpiresOn = expiresOn1
            };

            var entryLink = new EntryLink();

            entryLink.SetAbsoluteExpiration(expiresOn2);

            // Act
            var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(entryLink);

            // Assert
            Assert.Equal(expiresOn2, cacheEntryOptions.AbsoluteExpiration);
        }
Exemplo n.º 4
0
        public void UpdateCacheContext_UsesAbsoluteExpirationSpecifiedOnEntryLink()
        {
            // Arrange
            var expiresOn    = DateTimeOffset.UtcNow.AddMinutes(7);
            var cache        = new MemoryCache(new MemoryCacheOptions());
            var cacheContext = new Mock <ICacheSetContext>(MockBehavior.Strict);

            cacheContext.Setup(c => c.SetAbsoluteExpiration(expiresOn))
            .Verifiable();
            var cacheTagHelper = new CacheTagHelper
            {
                MemoryCache = cache
            };

            var entryLink = new EntryLink();

            entryLink.SetAbsoluteExpiration(expiresOn);

            // Act
            cacheTagHelper.UpdateCacheContext(cacheContext.Object, entryLink);

            // Assert
            cacheContext.Verify();
        }