コード例 #1
0
            public async Task CachesSettings()
            {
                SetCacheTime(ODataCachedEndpoint.GetSpecificPackage, 300);
                var target = new ODataCacheOutputAttribute(ODataCachedEndpoint.GetSpecificPackage, 100)
                {
                    ReloadDuration = TimeSpan.FromHours(1),
                };

                target.OnActionExecuting(ActionContext);
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                SetCacheTime(ODataCachedEndpoint.GetSpecificPackage, 600);
                Cache.ResetCalls();
                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.Is <DateTimeOffset>(e => before.AddSeconds(300) <= e && e <= after.AddSeconds(300)),
                        null),
                    Times.Once);
            }
コード例 #2
0
            public async Task RevertsToDefaultValueWhenFeatureFlagIsTurnedOff()
            {
                SetCacheTime(ODataCachedEndpoint.GetSpecificPackage, 600);
                var target = new ODataCacheOutputAttribute(ODataCachedEndpoint.GetSpecificPackage, 100)
                {
                    ReloadDuration = TimeSpan.Zero,
                };

                target.OnActionExecuting(ActionContext);
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                FeatureFlagService.Setup(x => x.AreDynamicODataCacheDurationsEnabled()).Returns(false);
                Cache.ResetCalls();
                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.Is <DateTimeOffset>(e => before.AddSeconds(100) <= e && e <= after.AddSeconds(100)),
                        null),
                    Times.Once);
            }
コード例 #3
0
            public async Task HasCorrectDefaultConfiguredCacheTime(ODataCachedEndpoint endpoint)
            {
                var cacheTime = DefaultCacheTime[endpoint];
                var target    = new ODataCacheOutputAttribute(endpoint, 0);

                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                if (cacheTime <= 0)
                {
                    Cache.Verify(
                        x => x.Add(
                            It.IsAny <string>(),
                            It.IsAny <object>(),
                            It.IsAny <DateTimeOffset>(),
                            It.IsAny <string>()),
                        Times.Never);
                }
                else
                {
                    Cache.Verify(
                        x => x.Add(
                            It.IsAny <string>(),
                            It.IsAny <object>(),
                            It.Is <DateTimeOffset>(e => before.AddSeconds(cacheTime) <= e && e <= after.AddSeconds(cacheTime)),
                            null),
                        Times.Once);
                }
            }
コード例 #4
0
            public async Task CanUseZeroFromConfiguration()
            {
                SetCacheTime(ODataCachedEndpoint.GetSpecificPackage, 0);
                var target = new ODataCacheOutputAttribute(ODataCachedEndpoint.GetSpecificPackage, 100);

                target.OnActionExecuting(ActionContext);

                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.IsAny <DateTimeOffset>(),
                        It.IsAny <string>()),
                    Times.Never);
            }
コード例 #5
0
            public async Task CanUseZeroWhenConfigurationIsTurnedOff()
            {
                SetCacheTime(ODataCachedEndpoint.GetSpecificPackage, 600);
                var target = new ODataCacheOutputAttribute(ODataCachedEndpoint.GetSpecificPackage, 0);

                FeatureFlagService.Setup(x => x.AreDynamicODataCacheDurationsEnabled()).Returns(false);
                target.OnActionExecuting(ActionContext);

                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.IsAny <DateTimeOffset>(),
                        It.IsAny <string>()),
                    Times.Never);
            }
コード例 #6
0
            public async Task DoesNotCacheHijackTrueAndGetSpecificPackage()
            {
                ActionContext.ActionArguments["hijack"] = false;
                var target = new ODataCacheOutputAttribute(ODataCachedEndpoint.GetSpecificPackage, 100);

                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.IsAny <DateTimeOffset>(),
                        null),
                    Times.Never);
            }
コード例 #7
0
            public async Task CacheHijackFalseOrNonGetSpecificPackage(ODataCachedEndpoint endpoint, bool hijack)
            {
                ActionContext.ActionArguments["hijack"] = hijack;
                var target = new ODataCacheOutputAttribute(endpoint, 100);

                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.IsAny <DateTimeOffset>(),
                        null),
                    Times.Once);
            }
コード例 #8
0
            public async Task ObservesConfiguredValue(ODataCachedEndpoint endpoint)
            {
                var cacheTime = 600;

                SetCacheTime(endpoint, cacheTime);
                var target = new ODataCacheOutputAttribute(endpoint, 100);

                target.OnActionExecuting(ActionContext);

                var before = DateTimeOffset.Now;
                await target.OnActionExecutedAsync(ActionExecutedContext, CancellationToken.None);

                var after = DateTimeOffset.Now;

                Cache.Verify(
                    x => x.Add(
                        It.IsAny <string>(),
                        It.IsAny <object>(),
                        It.Is <DateTimeOffset>(e => before.AddSeconds(cacheTime) <= e && e <= after.AddSeconds(cacheTime)),
                        null),
                    Times.Once);
            }