public async Task Should_cache_days_usage()
        {
            var f = DateTime.Today;
            var t = DateTime.Today.AddDays(10);

            A.CallTo(() => inner.GetPreviousCallsAsync(key, f, t))
            .Returns(120);

            var result1 = await sut.GetPreviousCallsAsync(key, f, t);

            var result2 = await sut.GetPreviousCallsAsync(key, f, t);

            Assert.Equal(120, result1);
            Assert.Equal(120, result2);

            A.CallTo(() => inner.GetPreviousCallsAsync(key, f, t))
            .MustHaveHappened(Repeated.Exactly.Once);
        }
Ejemplo n.º 2
0
        public Task <long> GetPreviousCallsAsync(string key, DateTime fromDate, DateTime toDate)
        {
            Guard.NotNull(key);

            var cacheKey = string.Join("$", "Usage", nameof(GetPreviousCallsAsync), key, fromDate, toDate);

            return(Cache.GetOrCreateAsync(cacheKey, entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = CacheDuration;

                return inner.GetPreviousCallsAsync(key, fromDate, toDate);
            }));
        }