Exemple #1
0
        public async Task GetResponseAsync_ReturnsCachedResponse(ErgastResponse expectedResponse)
        {
            Cache.Get <ErgastResponse>(null).ReturnsForAnyArgs(expectedResponse);

            var response = await Client.GetResponseAsync(NullRequest);

            response.Should().Be(expectedResponse);
        }
Exemple #2
0
        public void CachedResponseIsReturned(string url, ErgastResponse response)
        {
            // Arrange
            Cache.CacheEntryLifetime = TimeSpan.FromMinutes(1);
            Cache.AddOrReplace(url, response);

            // Act
            var cachedResponse = Cache.Get <ErgastResponse>(url);

            // Assert
            cachedResponse.Should().Be(response);
        }
        public void AddOrReplace(string url, ErgastResponse response)
        {
            var expiration = DateTimeOffset.UtcNow + CacheEntryLifetime;

            var entry = new CacheEntry <ErgastResponse>
            {
                Item       = response,
                Expiration = expiration
            };

            Cache[url] = entry;
        }
Exemple #4
0
 public void AddOrReplace(string url, ErgastResponse response)
 {
     Cache.Set(url, response, DateTimeOffset.UtcNow + CacheEntryLifetime);
 }