当前位置: 首页>>代码示例>>C#>>正文


C# CacheTagHelper.UpdateCacheContext方法代码示例

本文整理汇总了C#中Microsoft.AspNet.Mvc.TagHelpers.CacheTagHelper.UpdateCacheContext方法的典型用法代码示例。如果您正苦于以下问题:C# CacheTagHelper.UpdateCacheContext方法的具体用法?C# CacheTagHelper.UpdateCacheContext怎么用?C# CacheTagHelper.UpdateCacheContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.AspNet.Mvc.TagHelpers.CacheTagHelper的用法示例。


在下文中一共展示了CacheTagHelper.UpdateCacheContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateCacheContext_CopiesTriggersFromEntryLink

        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);
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:29,代码来源:CacheTagHelperTest.cs

示例2: UpdateCacheContext_SetsCachePreservationPriority

        public void UpdateCacheContext_SetsCachePreservationPriority()
        {
            // Arrange
            var priority = CachePreservationPriority.High;
            var cache = new MemoryCache(new MemoryCacheOptions());
            var cacheContext = new Mock<ICacheSetContext>();
            cacheContext.Setup(c => c.SetPriority(priority))
                        .Verifiable();
            var cacheTagHelper = new CacheTagHelper
            {
                MemoryCache = cache,
                Priority = priority
            };

            // Act
            cacheTagHelper.UpdateCacheContext(cacheContext.Object, new EntryLink());

            // Assert
            cacheContext.Verify();
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:20,代码来源:CacheTagHelperTest.cs

示例3: UpdateCacheContext_SetsSlidingExpiration_IfExpiresSlidingIsSet

        public void UpdateCacheContext_SetsSlidingExpiration_IfExpiresSlidingIsSet()
        {
            // Arrange
            var expiresSliding = TimeSpan.FromSeconds(37);
            var cache = new MemoryCache(new MemoryCacheOptions());
            var cacheContext = new Mock<ICacheSetContext>();
            cacheContext.Setup(c => c.SetSlidingExpiration(expiresSliding))
                        .Verifiable();
            var cacheTagHelper = new CacheTagHelper
            {
                MemoryCache = cache,
                ExpiresSliding = expiresSliding
            };

            // Act
            cacheTagHelper.UpdateCacheContext(cacheContext.Object, new EntryLink());

            // Assert
            cacheContext.Verify();
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:20,代码来源:CacheTagHelperTest.cs

示例4: UpdateCacheContext_PrefersAbsoluteExpirationSpecifiedOnEntryLinkOverExpiresOn

        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();
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:31,代码来源:CacheTagHelperTest.cs

示例5: UpdateCacheContext_UsesAbsoluteExpirationSpecifiedOnEntryLink

        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();
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:22,代码来源:CacheTagHelperTest.cs

示例6: UpdateCacheContext_SetsAbsoluteExpiration_IfExpiresOnIsSet

        public void UpdateCacheContext_SetsAbsoluteExpiration_IfExpiresOnIsSet()
        {
            // Arrange
            var expiresOn = DateTimeOffset.UtcNow.AddMinutes(4);
            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,
                ExpiresOn = expiresOn
            };

            // Act
            cacheTagHelper.UpdateCacheContext(cacheContext.Object, new EntryLink());

            // Assert
            cacheContext.Verify();
        }
开发者ID:AndersBillLinden,项目名称:Mvc,代码行数:20,代码来源:CacheTagHelperTest.cs


注:本文中的Microsoft.AspNet.Mvc.TagHelpers.CacheTagHelper.UpdateCacheContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。