File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ namespace Polly.Caching;
44/// <summary>
55/// Defines a ttl strategy which will cache items for a TimeSpan which may be influenced by data in the execution context.
66/// </summary>
7- #pragma warning disable CA1062 // Validate arguments of public methods
87public class ContextualTtl : ITtlStrategy
98{
109 /// <summary>
@@ -28,6 +27,11 @@ public class ContextualTtl : ITtlStrategy
2827 /// <returns>TimeSpan.</returns>
2928 public Ttl GetTtl ( Context context , object ? result )
3029 {
30+ if ( context is null )
31+ {
32+ throw new ArgumentNullException ( nameof ( context ) ) ;
33+ }
34+
3135 if ( ! context . ContainsKey ( TimeSpanKey ) )
3236 {
3337 return NoTtl ;
Original file line number Diff line number Diff line change 22
33public class ContextualTtlSpecs
44{
5+ [ Fact ]
6+ public void Should_throw_when_context_is_null ( )
7+ {
8+ Context context = null ! ;
9+ Action action = ( ) => new ContextualTtl ( ) . GetTtl ( context , null ) ;
10+ action . Should ( ) . Throw < ArgumentNullException > ( ) . And . ParamName . Should ( ) . Be ( "context" ) ;
11+ }
12+
513 [ Fact ]
614 public void Should_return_zero_if_no_value_set_on_context ( ) =>
715 new ContextualTtl ( ) . GetTtl ( new Context ( "someOperationKey" ) , null ) . Timespan . Should ( ) . Be ( TimeSpan . Zero ) ;
You can’t perform that action at this time.
0 commit comments