示例#1
0
        public void UpdateCacheContext_CopiesTriggersFromEntryLink()
        {
            // Arrange
            var expiresSliding = TimeSpan.FromSeconds(30);
            var expected       = new[] { Mock.Of <IExpirationTrigger>(), Mock.Of <IExpirationTrigger>() };
            var triggers       = new List <IExpirationTrigger>();
            var cache          = new MemoryCache(new MemoryCacheOptions());
            var cacheContext   = new Mock <ICacheSetContext>();

            cacheContext.Setup(c => c.SetSlidingExpiration(expiresSliding))
            .Verifiable();
            cacheContext.Setup(c => c.AddExpirationTrigger(It.IsAny <IExpirationTrigger>()))
            .Callback <IExpirationTrigger>(triggers.Add)
            .Verifiable();
            var cacheTagHelper = new CacheTagHelper
            {
                MemoryCache    = cache,
                ExpiresSliding = expiresSliding
            };

            var entryLink = new EntryLink();

            entryLink.AddExpirationTriggers(expected);

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

            // Assert
            cacheContext.Verify();
            Assert.Equal(expected, triggers);
        }
        public void UpdateCacheEntryOptions_CopiesTriggersFromEntryLink()
        {
            // Arrange
            var expiresSliding = TimeSpan.FromSeconds(30);
            var expected       = new[] { Mock.Of <IExpirationTrigger>(), Mock.Of <IExpirationTrigger>() };
            var cache          = new MemoryCache(new MemoryCacheOptions());
            var cacheTagHelper = new CacheTagHelper(cache)
            {
                ExpiresSliding = expiresSliding
            };

            var entryLink = new EntryLink();

            entryLink.AddExpirationTriggers(expected);

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

            // Assert
            Assert.Equal(expected, cacheEntryOptions.Triggers.ToArray());
        }