Exemple #1
0
        public async Task Log_GetSet_WithAbsoluteExpiration()
        {
            // Arrange
            var expiration = DateTime.UtcNow.AddDays(1);

            _redcache.GetOrSet(Arg.Any <string>(), Arg.Any <Func <string> >(), Arg.Any <DateTime>()).Returns("value");

            // Act
            var result = await _redcacheDecorator.GetOrSet("key", () => "value", expiration);

            // Assert
            _logger.Received().Log(Arg.Any <LogLevel>(), Arg.Any <string>());
            _redcache.Received().GetOrSet(Arg.Is("key"), Arg.Any <Func <string> >(), Arg.Is(expiration)).Wait();
            result.Should().Be("value");
        }
Exemple #2
0
 public async Task <IEnumerable <WeatherForecast> > Get()
 {
     return(await _redcache.GetOrSet("weather", () =>
     {
         var rng = new Random();
         return Enumerable.Range(1, 5).Select(index => new WeatherForecast
         {
             ForecastDate = DateTime.UtcNow,
             Date = DateTime.Now.AddDays(index),
             TemperatureC = rng.Next(-20, 55),
             Summary = Summaries[rng.Next(Summaries.Length)]
         })
         .ToArray();
     }, TimeSpan.FromMinutes(1)));
 }