8
8
using System . Security . Claims ;
9
9
using System . Security . Cryptography ;
10
10
using System . Text ;
11
+ using System . Text . Encodings . Web ;
11
12
using System . Threading ;
12
13
using System . Threading . Tasks ;
13
14
using Microsoft . AspNetCore . Html ;
@@ -250,12 +251,12 @@ public async Task ProcessAsync_DoesNotCache_IfDisabled()
250
251
var id = "unique-id" ;
251
252
var childContent = "original-child-content" ;
252
253
var cache = new Mock < IMemoryCache > ( ) ;
253
- var value = new DefaultTagHelperContent ( ) . SetContent ( "ok" ) ;
254
- cache . Setup ( c => c . Set (
255
- /*key*/ It . IsAny < string > ( ) ,
256
- /*value */ value ,
257
- /*optons*/ It . IsAny < MemoryCacheEntryOptions > ( ) ) )
258
- . Returns ( value ) ;
254
+ var value = new Mock < ICacheEntry > ( ) ;
255
+ value . Setup ( c => c . Value ) . Returns ( new DefaultTagHelperContent ( ) . SetContent ( "ok" ) ) ;
256
+ cache . Setup ( c => c . CreateEntry (
257
+ /*key */ It . IsAny < string > ( ) ) )
258
+ . Returns ( ( object key ) => value . Object )
259
+ . Verifiable ( ) ;
259
260
object cacheResult ;
260
261
cache . Setup ( c => c . TryGetValue ( It . IsAny < string > ( ) , out cacheResult ) )
261
262
. Returns ( false ) ;
@@ -274,10 +275,8 @@ public async Task ProcessAsync_DoesNotCache_IfDisabled()
274
275
275
276
// Assert
276
277
Assert . Equal ( childContent , tagHelperOutput . Content . GetContent ( ) ) ;
277
- cache . Verify ( c => c . Set (
278
- /*key*/ It . IsAny < string > ( ) ,
279
- /*value*/ It . IsAny < object > ( ) ,
280
- /*options*/ It . IsAny < MemoryCacheEntryOptions > ( ) ) ,
278
+ cache . Verify ( c => c . CreateEntry (
279
+ /*key*/ It . IsAny < string > ( ) ) ,
281
280
Times . Never ) ;
282
281
}
283
282
@@ -288,13 +287,12 @@ public async Task ProcessAsync_ReturnsCachedValue_IfEnabled()
288
287
var id = "unique-id" ;
289
288
var childContent = "original-child-content" ;
290
289
var cache = new Mock < IMemoryCache > ( ) ;
291
- var value = new DefaultTagHelperContent ( ) . SetContent ( "ok" ) ;
292
- cache . Setup ( c => c . CreateLinkingScope ( ) ) . Returns ( new Mock < IEntryLink > ( ) . Object ) ;
293
- cache . Setup ( c => c . Set (
294
- /*key*/ It . IsAny < string > ( ) ,
295
- /*value*/ It . IsAny < object > ( ) ,
296
- /*options*/ It . IsAny < MemoryCacheEntryOptions > ( ) ) )
297
- . Returns ( value ) ;
290
+ var value = new Mock < ICacheEntry > ( ) ;
291
+ value . Setup ( c => c . Value ) . Returns ( new DefaultTagHelperContent ( ) . SetContent ( "ok" ) ) ;
292
+ value . Setup ( c => c . ExpirationTokens ) . Returns ( new List < IChangeToken > ( ) ) ;
293
+ cache . Setup ( c => c . CreateEntry (
294
+ /*key*/ It . IsAny < string > ( ) ) )
295
+ . Returns ( ( object key ) => value . Object ) ;
298
296
object cacheResult ;
299
297
cache . Setup ( c => c . TryGetValue ( It . IsAny < string > ( ) , out cacheResult ) )
300
298
. Returns ( false ) ;
@@ -318,10 +316,8 @@ public async Task ProcessAsync_ReturnsCachedValue_IfEnabled()
318
316
Assert . Equal ( childContent , tagHelperOutput . Content . GetContent ( ) ) ;
319
317
320
318
// There are two calls to set (for the TCS and the processed value)
321
- cache . Verify ( c => c . Set (
322
- /*key*/ It . IsAny < string > ( ) ,
323
- /*value*/ It . IsAny < object > ( ) ,
324
- /*options*/ It . IsAny < MemoryCacheEntryOptions > ( ) ) ,
319
+ cache . Verify ( c => c . CreateEntry (
320
+ /*key*/ It . IsAny < string > ( ) ) ,
325
321
Times . Exactly ( 2 ) ) ;
326
322
}
327
323
@@ -443,51 +439,7 @@ public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresOnIsSet()
443
439
// Assert
444
440
Assert . Equal ( expiresOn , cacheEntryOptions . AbsoluteExpiration ) ;
445
441
}
446
-
447
- [ Fact ]
448
- public void UpdateCacheEntryOptions_UsesAbsoluteExpirationSpecifiedOnEntryLink ( )
449
- {
450
- // Arrange
451
- var expiresOn = DateTimeOffset . UtcNow . AddMinutes ( 7 ) ;
452
- var cache = new MemoryCache ( new MemoryCacheOptions ( ) ) ;
453
- var cacheTagHelper = new CacheTagHelper ( cache , new HtmlTestEncoder ( ) )
454
- {
455
- } ;
456
-
457
- var entryLink = new EntryLink ( ) ;
458
- entryLink . SetAbsoluteExpiration ( expiresOn ) ;
459
-
460
- // Act
461
- var cacheEntryOptions = cacheTagHelper . GetMemoryCacheEntryOptions ( ) ;
462
- cacheEntryOptions . AddEntryLink ( entryLink ) ;
463
-
464
- // Assert
465
- Assert . Equal ( expiresOn , cacheEntryOptions . AbsoluteExpiration ) ;
466
- }
467
-
468
- [ Fact ]
469
- public void UpdateCacheEntryOptions_PrefersAbsoluteExpirationSpecifiedOnEntryLinkOverExpiresOn ( )
470
- {
471
- // Arrange
472
- var expiresOn1 = DateTimeOffset . UtcNow . AddDays ( 12 ) ;
473
- var expiresOn2 = DateTimeOffset . UtcNow . AddMinutes ( 4 ) ;
474
- var cache = new MemoryCache ( new MemoryCacheOptions ( ) ) ;
475
- var cacheTagHelper = new CacheTagHelper ( cache , new HtmlTestEncoder ( ) )
476
- {
477
- ExpiresOn = expiresOn1
478
- } ;
479
-
480
- var entryLink = new EntryLink ( ) ;
481
- entryLink . SetAbsoluteExpiration ( expiresOn2 ) ;
482
-
483
- // Act
484
- var cacheEntryOptions = cacheTagHelper . GetMemoryCacheEntryOptions ( ) ;
485
- cacheEntryOptions . AddEntryLink ( entryLink ) ;
486
-
487
- // Assert
488
- Assert . Equal ( expiresOn2 , cacheEntryOptions . AbsoluteExpiration ) ;
489
- }
490
-
442
+
491
443
[ Fact ]
492
444
public void UpdateCacheEntryOptions_SetsAbsoluteExpiration_IfExpiresAfterIsSet ( )
493
445
{
@@ -541,30 +493,7 @@ public void UpdateCacheEntryOptions_SetsCachePreservationPriority()
541
493
// Assert
542
494
Assert . Equal ( priority , cacheEntryOptions . Priority ) ;
543
495
}
544
-
545
- [ Fact ]
546
- public void UpdateCacheEntryOptions_CopiesTriggersFromEntryLink ( )
547
- {
548
- // Arrange
549
- var expiresSliding = TimeSpan . FromSeconds ( 30 ) ;
550
- var expected = new [ ] { Mock . Of < IChangeToken > ( ) , Mock . Of < IChangeToken > ( ) } ;
551
- var cache = new MemoryCache ( new MemoryCacheOptions ( ) ) ;
552
- var cacheTagHelper = new CacheTagHelper ( cache , new HtmlTestEncoder ( ) )
553
- {
554
- ExpiresSliding = expiresSliding
555
- } ;
556
-
557
- var entryLink = new EntryLink ( ) ;
558
- entryLink . AddExpirationTokens ( expected ) ;
559
-
560
- // Act
561
- var cacheEntryOptions = cacheTagHelper . GetMemoryCacheEntryOptions ( ) ;
562
- cacheEntryOptions . AddEntryLink ( entryLink ) ;
563
-
564
- // Assert
565
- Assert . Equal ( expected , cacheEntryOptions . ExpirationTokens . ToArray ( ) ) ;
566
- }
567
-
496
+
568
497
[ Fact ]
569
498
public async Task ProcessAsync_UsesExpiresAfter_ToExpireCacheEntry ( )
570
499
{
@@ -961,6 +890,17 @@ private static TagHelperOutput GetTagHelperOutput(
961
890
} ) ;
962
891
}
963
892
893
+ private static TagHelperOutput GetTagHelperOutput (
894
+ Func < bool , HtmlEncoder , Task < TagHelperContent > > processAsync )
895
+ {
896
+ var attributes = new TagHelperAttributeList { { "attr" , "value" } } ;
897
+
898
+ return new TagHelperOutput (
899
+ "cache" ,
900
+ attributes ,
901
+ getChildContentAsync : processAsync ) ;
902
+ }
903
+
964
904
private static string GetHashedBytes ( string input )
965
905
{
966
906
using ( var sha = SHA256 . Create ( ) )
0 commit comments