public void Should_return_func_result_using_context() { const string specialKey = "specialKey"; TimeSpan ttl = TimeSpan.FromMinutes(1); Func <Context, dynamic, Ttl> func = (context, result) => { return(context.OperationKey == specialKey ? new Ttl(TimeSpan.Zero) : new Ttl(result.Ttl)); }; ResultTtl <dynamic> ttlStrategy = new ResultTtl <dynamic>(func); ttlStrategy.GetTtl(new Context("someOperationKey"), new { Ttl = ttl }).Timespan.Should().Be(ttl); ttlStrategy.GetTtl(new Context(specialKey), new { Ttl = ttl }).Timespan.Should().Be(TimeSpan.Zero); }
public void Should_return_func_result() { TimeSpan ttl = TimeSpan.FromMinutes(1); Func <dynamic, Ttl> func = (result) => { return(new Ttl(result.Ttl)); }; ResultTtl <dynamic> ttlStrategy = new ResultTtl <dynamic>(func); Ttl retrieved = ttlStrategy.GetTtl(new Context("someOperationKey"), new { Ttl = ttl }); retrieved.Timespan.Should().Be(ttl); retrieved.SlidingExpiration.Should().BeFalse(); }